Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

oop - Global (shared) variables in Matlab GUI code behind. Is there better way to do it then using handles structure?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...