Issues with GUI not running properly

2 views (last 30 days)
Nick Bell
Nick Bell on 1 Oct 2012
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?

Answers (1)

Matt Fig
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
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...
Nick Bell
Nick Bell on 1 Oct 2012
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.

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!