Running a GUI requires opening the .fig file in GUIDE

若如初见. 提交于 2019-12-18 07:08:16

问题


I am trying to run a MATLAB GUI I have created. If I open the .fig file using GUIDE and press the run button there, it runs perfectly.

However, when I double-click the .fig file in the 'Current Folder' section of MATLAB, it seems to be unable to find the handles variable. This causes it to give an error whenever handles is used.

Why does this happen? Is there a fix/workaround?

I'm using MATLAB R2011, but I've tried it on R2012 as well. The code runs fine, and displays the GUI fine, but the moment it encounters the handles variable, it gives the following error:

Attempt to reference field of non-structure array.


回答1:


When you create a GUI using GUIDE, it should create both a .fig file and a .m file. To run it, you should run the .m file, rather than double-clicking the .fig file.

The .fig file just contains static information about the layout of the GUI - there is nothing executable in it that would initialise handles and so on.




回答2:


Well, always run .m file if you want to check your code and if you want to edit GUI go through guide command. If you open .fig file you'll get a file which you can't execute and you can't able to analyze that. corresponding .m file will have respective functions for your GUI.



来源:https://stackoverflow.com/questions/15678762/running-a-gui-requires-opening-the-fig-file-in-guide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!