calling one gui from another.

6 ビュー (過去 30 日間)
Physiker192 2014 年 11 月 3 日
回答済み: Geoff Hayes 2014 年 11 月 3 日
hello, let's say i have two guis the first (named plotfct) contains only a pushbutton (tag: plota1) and the other (plaxes1) contains only axes (tag: axes1). what i want to do is to click on the button in the first and get the plot in the second. what i have is the next:
function plota1_Callback(hObject, eventdata, handles)
% hObject handle to plota1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
any help would be appreciated. thanks in advance.

回答 (3 件)

Image Analyst
Image Analyst 2014 年 11 月 3 日
It would be so much easier if they were in the same GUI. Any reason why you're not doing that?
  2 件のコメント
Image Analyst
Image Analyst 2014 年 11 月 3 日
You can use assignin() and evalin() to put/get variables from the base workspace. Did you read the link?


Julia 2014 年 11 月 3 日
I used something like this in the callback function in the first gui:
run GUI2;
handles.GUI2 = GUI2(handles.GUI1);
handlesVariableName = guidata(handles.GUI2);
set(handlesVariableName.pop_boom,'String',chosen); % pop_boom is the name of a drop down list in GUI2, chosen is the value I want to transfer
And in the opening function of the second gui:
handles.GUI1 = varargin{1};
% Choose default command line output for GUI2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
  5 件のコメント
Adam 2014 年 11 月 3 日
Getting GUIs to talk to each other is not particularly basic in Matlab unfortunately so it doesn't generally fall under the heading of "easy"!


Geoff Hayes
Geoff Hayes 2014 年 11 月 3 日
Another possibility is to do something similar to Assuming that you are using GUIDE, you will need to set the second GUI's HandleVisibility property to on (use the GUIDE property inspector to do this) so that it can be visible to the first GUI. Now assuming that your second GUI is named (or tagged) as plaxes1, then, in your plota1_Callback do
function plota1_Callback(hObject, eventdata, handles)
h = findobj('Tag','plaxes1');
% if exists (not empty)
if ~isempty(h)
% get handles and other user-defined data associated to the other GUI
g2Handles = guidata(h);
% plot the curve
In the above, since the handle visibility of your second GUI is on, we can use findobj to look for the object whose tag is plaxes1. Here, we are assuming that the tag (another property of the GUI) has its value set to plaxes1. If you are using something else, then just insert that into the line of code. If findobj returns a (non-empty) handle, then we use guidata to get the handles (and user-defined data) of the second GUI. We can then use this structure to access the axes2 handle so that we can plot the data on it.
See attached code for an example.

Community Treasure Hunt

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

Start Hunting!

Translated by