Issues with GUI not running properly
3 views (last 30 days)
Show older comments
I have a GUI that I can't get to work properly. When I open the .m file and run it (with the green triangle) it works exactly as planned, but when I open the .fig file it doesn't work, coming up with "Attempt to reference field of non-structure array."
Any ideas as to why the GUI works when used one way, and not another?
0 Comments
Answers (1)
Matt Fig
on 1 Oct 2012
Edited: Matt Fig
on 1 Oct 2012
Yes, guide GUIs need to have the initialization code in the M-file run before the figure will work as you want. It is the nature of the beast.
You know that part of the code in the M-file that says, "DO NOT EDIT" at the beginning? That opens the figure and sets up the uicontrols to work with the callback functions and whatnot. If you merely open the figure, that code is not run and so those things are not set up and so won't work.
This mutual dependence on two separate entities is one of the reasons I started writing my own GUIs and never use guide anymore (unless I am answering questions here ;-)).
3 Comments
Matt Fig
on 1 Oct 2012
Edited: Matt Fig
on 1 Oct 2012
What is unclear? As I said, you simply cannot open the figure by itself and expect the GUI to work.
I don't know how to be more clear than that. MATLAB needs to run the code you pasted above to make the figure work correctly. The way you get MATLAB to run the code is to call the M-File name, which opens the figure and gets the GUI ready to go. Yes, you can also done this by pressing the green triangle in guide. But either way, this is how it is done...
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!