calling one gui from another.

8 visualizaciones (últimos 30 días)
Physiker192
Physiker192 el 3 de Nov. de 2014
Respondida: Geoff Hayes el 3 de Nov. de 2014
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)
x=0:0.1:5*pi;
y=2*sin(x);
plot(handles.plaxes1,x,y);
any help would be appreciated. thanks in advance.

Respuestas (3)

Image Analyst
Image Analyst el 3 de Nov. de 2014
It would be so much easier if they were in the same GUI. Any reason why you're not doing that?
  2 comentarios
Physiker192
Physiker192 el 3 de Nov. de 2014
Yeah i know. But it's my design i would like to present i would like to present it this way.
Image Analyst
Image Analyst el 3 de Nov. de 2014
You can use assignin() and evalin() to put/get variables from the base workspace. Did you read the link?

Iniciar sesión para comentar.


Julia
Julia el 3 de Nov. de 2014
Hi,
I used something like this in the callback function in the first gui:
run GUI2;
handles.GUI2 = GUI2(handles.GUI1);
guidata(handles.GUI1,handles);
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:
try
handles.GUI1 = varargin{1};
% Choose default command line output for GUI2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
catch
end
  5 comentarios
Julia
Julia el 3 de Nov. de 2014
I am not that experienced in using guis either. I just found some pieces of code and tried until it worked for me. Perhaps this is worth another try.
In:
try
handles.GUI1 = varargin{1};
% Choose default command line output for GUI2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
catch
end
GUI1 has to be the name of your first gui as you find it in the comments (generated by Matlab). Its all in uppercase letters.
Adam
Adam el 3 de Nov. de 2014
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"!

Iniciar sesión para comentar.


Geoff Hayes
Geoff Hayes el 3 de Nov. de 2014
Another possibility is to do something similar to http://www.mathworks.com/matlabcentral/answers/146215-pass-data-between-gui-s. 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)
x=0:0.1:5*pi;
y=2*sin(x);
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
plot(g2Handles.axes1,x,y);
end
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.

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by