Issues with GUI not running properly
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Matt Fig
2012-10-1
编辑:Matt Fig
2012-10-1
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 个评论
Matt Fig
2012-10-1
编辑:Matt Fig
2012-10-1
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...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!