3

I have spent some time lately creating complex Matlab GUI tool. I'm using GUIDE GUI builder.

I dislike the way Matlab manages global variables in code behind (the .m file with functions). If I want to share data between function calls I have to store them in handles structure that is given as a parameter to every function call. I consider it to be bug prone as I have to mind storing and updating handles all the time. It is rather unnatural for me to handle global variables this way. Using appdata is even worse.

Is it possible to use class as a code behind for GUI? All the callbacks would be methods so they would receive obj as a parameter and I could store global variables in class properties. This seems to me to to be much clearer.

It is just an idea and it may be not possible at all... But if there is better practise how to deal with global variables in Matlab GUI then please suggest it.

Rasto
  • 17,204
  • 47
  • 154
  • 245

1 Answers1

3

Example using a MATLAB Class to control a GUI from MATLAB File Exchange.

slitvinov
  • 5,693
  • 20
  • 31
  • +1 interesting. So I see I'm not the only one who would prefer more structural way for creating GUI code behind. I'm studying the code you recommended and I'll be back with some comments when I'm done. – Rasto Jul 22 '12 at 10:33
  • You can also consider using java components. – slitvinov Jul 22 '12 at 12:31
  • Can you provide more detailed explanation on Java components please? I have never used any java code with Matlab. – Rasto Jul 25 '12 at 18:00