plotting from one gui into another

조회 수: 2 (최근 30일)
Physiker192 2014년 11월 3일
댓글: Zoltán Csáti 2014년 11월 3일
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
Physiker192 2014년 11월 3일
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 2014년 11월 3일
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!

댓글을 달려면 로그인하십시오.

답변 (1개)

Zoltán Csáti
Zoltán Csáti 2014년 11월 3일
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});
function createPlot(varargin)
S = varargin{3};
line('XData',[0 1],'YData',[0 1],'Parent',S.axes);
  댓글 수: 4
Physiker192 2014년 11월 3일
okay thanks a lot :D
Zoltán Csáti
Zoltán Csáti 2014년 11월 3일
You are welcome. Feel free to ask if you get stuck.

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by