plotting from one gui into another
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
2014-11-3
I use the programmatic way of creating GUIs but the following should work in GUIDE too.
- create the first GUI with a pushbutton
- create the second GUI with an axes object
- 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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!