plotting from one gui into another

2 visualizzazioni (ultimi 30 giorni)
Physiker192
Physiker192 il 3 Nov 2014
Commentato: Zoltán Csáti il 3 Nov 2014
Hello, i have a little problem, let's suppose i have 2 GUIs created in guide, and for simplicity let's take the example: i only have a pushbutton(b1) in the first (GUI_1) and an axes (a1) in the other (GUI_2) what i want when i push the button in the first is to get the plot in the second. I am able to plot it on the same figure but It is kinda necessary for me to do it in separate figures, and i am new to GUI. can anybody help me in writing the code? thanks in advance :D
  3 Commenti
Physiker192
Physiker192 il 3 Nov 2014
yeah i guess this is the case. i don't know how to make them dependent. i tried to build an easy example like: x=0:pi/4:5*pi; y=sinx; and tried to plot it but i can't get the job done. thank you :D
Adam
Adam il 3 Nov 2014
Well you can easily make one dependent on the other by opening it from e.g. a callback of the first GUI by just calling it by the name of its .m/.fig file.
If you do this then you can pass information from one to the other. Unfortunately this works best if it is the 2nd, spawned GUI, that needs to know something from the first GUI and is not as easy if you want two-way communication without the 1st window waiting for the second to be closed.
If you wanted to use custom-written objects then it is very easy to achieve two-way communication.
Otherwise you will likely need to use findobj or findall and make sure you give unique and understandable tags to the relevant parts of your two GUIs that need to be retrieved from each other.
If you do that then findobj should allow you to find an object by its tag. I don't use this method myself so I can't remember when you need to use findobj and when you need to use findall. I think findall will ignore the hidden property of a graphics handle to allow you to find anything. This is not good programming style, but will work if you aren't too fussed about good programming style!

Accedi per commentare.

Risposte (1)

Zoltán Csáti
Zoltán Csáti il 3 Nov 2014
I use the programmatic way of creating GUIs but the following should work in GUIDE too.
  1. create the first GUI with a pushbutton
  2. create the second GUI with an axes object
  3. create a callback for the pushbutton so that it plots on the specific axes. It can be done as
function makegui
S.fig1 = figure;
S.fig2 = figure;
S.btn = uicontrol('Parent',S.fig1, 'Style','push');
S.axes = axes('Parent',S.fig2);
set(S.btn, 'Callback',{@createPlot,S});
end
function createPlot(varargin)
S = varargin{3};
line('XData',[0 1],'YData',[0 1],'Parent',S.axes);
end
  4 Commenti
Physiker192
Physiker192 il 3 Nov 2014
okay thanks a lot :D
Zoltán Csáti
Zoltán Csáti il 3 Nov 2014
You are welcome. Feel free to ask if you get stuck.

Accedi per commentare.

Categorie

Scopri di più su Graphics Objects in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by