Undefined function when successfully opening .fig
2 views (last 30 days)
Show older comments
I am opening a new GUI window when a user clicks a button in an existing window. To do this, in the button callback I issue the command
gui2Handle = open('GuiWindow2.fig');
However, Matlab then prints the error
Undefined function 'GuiWindow2' for input arguments of type 'char'.
which is strange because I'm not giving any arguments at all. It seems like for some people this error results when there's an issue with the path, but when I type
which GuiWindow2.fig
into the command window, I get the correct directory. Additionally, after Matlab prints the error about input arguments of type 'char' a couple of times, it then goes on to open the figure, and so far I haven't found anything about it that doesn't work.
I've tried debugging with "if error" but although it stops as soon as it prints the undefined function error, it doesn't bring me to any line in the code, then if I step through, it might print the error once more and then the figure appears, but the debugger never highlights any lines of code.
Any ideas on why this error is appearing and how to remove it?
0 Comments
Answers (2)
Star Strider
on 24 Jul 2014
3 Comments
Star Strider
on 24 Jul 2014
Still guessing here, but what happens when you do:
[Q1,Q2,Q3] = fileparts(which('GuiWindow2.fig'));
X = dir([Q1 '\*.fig'])
My guess is that it’s defaulting to the wrong directory. (I tested this code on my system, but with a different filename. It produces the correct results when I run it.)
Geoff Hayes
on 24 Jul 2014
The GUI figure files are not meant to be executed. While it will "launch" if you double-click on it, none of the initializations (that the code needs) will occur.
Try adding the following line in your callback
run('GuiWindow2')
This will call the m-file of the GuiWindow2 code and launch the GUI. I have tried this from the Command Window and from the callback of a push button in a simple GUI.
0 Comments
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!