MATLAB: Plotting data from one GUI to other

plotsharing data

Hello Everyone
I have a doubt regarding plotting the data that is being generated in one GUI, in another window which consists of just an axes and a pushbutton (Save as). I am using the function 'plot' in the first GUI and want to pass the handle of the axes (present in the second GUI) to the first so that data generated will be plot in the second GUI. I am trying to use the sharing method with guidata.
Thanks in advance.

Best Answer

You'll need to store handle of the 2nd figure/GUI in root. You can achieve this by typing the following code in opening function of second gui:
function SecondGuiName_OpeningFcn(hObject, eventdata, handles, varargin)
setappdata(0 , 'SecondGui', gcf) % stores handle to this gui in root
And now in push button callback of your main gui:
SecondGuiName; % invokes second gui
SecondGui = getappdata(0 , 'SecondGui') % collects handle to the second gui
h = findobj(SecondGui , 'type' , 'axes') % looks for object of type...
% axes in the second gui
axes(h)
plot(xdata,ydata)
Related Question