Undefined function when successfully opening .fig
이전 댓글 표시
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?
답변 (2개)
Star Strider
2014년 7월 24일
0 개 추천
댓글 수: 3
Forrest
2014년 7월 24일
Star Strider
2014년 7월 24일
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
2014년 7월 24일
Geoff Hayes
2014년 7월 24일
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.
카테고리
도움말 센터 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!