Issues with GUI not running properly

조회 수: 5 (최근 30일)
Nick Bell
Nick Bell 2012년 10월 1일
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?

답변 (1개)

Matt Fig
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
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...
Nick Bell
Nick Bell 2012년 10월 1일
Sorry I hadn't seen the editted version before I replied.
I didn't realise that opening the .fig wouldn't run the GUI as I expected it to, I assumed there was a problem somewhere (as I said, I'm new to GUIs). It's going to be compiled into a .exe so won't be dependent on being manually run, I just wanted to make sure I hadn't built something that wouldn't work.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by