How to call a different GUI through a push button?

3 ビュー (過去 30 日間)
BSantos
BSantos 2013 年 7 月 29 日
回答済み: Ong Kian 2016 年 4 月 4 日
Hey!
I'm hoping you guys can help me out with something.
First let me give an overview of my project: I have two separate GUIs, saved in two different folders, which one of them with their own functions and different purpose. While running GUI_1 (let's call it like that), the user can push a button and start GUI_2.
Now the problem: If, I do not run (F5) GUI_2 first, add it to the path of GUI_1, I get an error. Otherwise it works just fine!
The Error message:
Undefined function or variable 'Main_GUI_2'.
Error in Databsvs1>StartDataAnalysis_Callback (line 799)
Main_GUI_2;
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Databsvs1 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Databsvs1('StartDataAnalysis_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
The question: How can I add the path 'automatically', once the user pushes the button to start GUI_2? Maybe it's important to refer, that both GUIs are not compiled yet (just .m files).
Thanks in advance!!!!
Greets, BS.

採用された回答

David Sanchez
David Sanchez 2013 年 7 月 29 日
Since the second GUI is in another directory, use the function _run_to call the second GUI, adding the full path to the second GUI:
run('C\:......path_to_GUI.\GUI_name')
This way, the second GUI will open when call from wherever you call it.

その他の回答 (2 件)

Jan
Jan 2013 年 7 月 29 日
What does "add the path" mean here? Actually the folders, which contain the M-files, should be added to the Matlab path by addpath and savepath, or the pathtool GUI. To support e.g. different versions of the GUIs, this is better done manually.
But it would work by:
addpath('D:\MFiles\GUIs\GUI2\', '-end');
Main_GUI_2;
Or:
myPath = fileparts(mfilename('fullpath'));
gui2Path = fullfile(myPath, '..', 'GUI2');
gui2Path = GetFullPath(gui2Path);
addpath(gui2Path, '-end');
With GetFullPath downlöoaded from the FileExchange.
Of course the folder name must be adjusted to your setup. But again: I would definitely avoid to hard code a folder name in the code.
  1 件のコメント
BSantos
BSantos 2013 年 7 月 29 日
Jan thank you!
I would also like to avoid to hard code a folder name. Will try both solutions you presented. So far, the one from David Sanchez, works just fine.

サインインしてコメントする。


Ong Kian
Ong Kian 2016 年 4 月 4 日
Ty for the lesson. Yes, do not use hard file path. For the first time using GUI, i write this...
close(page1)
run(page2)
%this works when running but give me an error in the command window
%The error gone by add the path
run('C\:......path_to_GUI.\GUI_name')

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by