Undefined function when successfully opening .fig

2 views (last 30 days)
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?

Answers (2)

Star Strider
Star Strider on 24 Jul 2014
Wild guess here, but perhaps openfig is what you want?
  3 Comments
Star Strider
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.)
Forrest
Forrest on 24 Jul 2014
The .fig file and its corresponding .m file are in the directory I expect them to be in and the .fig is listed in X along with a few other .fig files.
It's not the same directory as the .m file that's calling it, however, there is another figure in the same directory as GuiWindow2 which is called in the same way without any errors.
Just double clicking on some of them in Matlab's directory tree, I noticed one other figure also gives that same error. The only thing that's obviously in common between them is that they both have popupmenu ui controls.

Sign in to comment.


Geoff Hayes
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.

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!