Plotting data from one GUI to other

조회 수: 11 (최근 30일)
nl2605
nl2605 2013년 7월 17일
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.

채택된 답변

Dishant Arora
Dishant Arora 2013년 7월 17일
편집: Dishant Arora 2013년 7월 17일
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)

추가 답변 (3개)

nl2605
nl2605 2013년 7월 18일
I tried it but it says invalid object handle. And shows an error at axes (h).

nl2605
nl2605 2013년 7월 18일
Hey it works. It was my own fault when it gave that error. Thanks a ton! :)

nl2605
nl2605 2013년 7월 18일
If my second GUI has two different axes then if I give the property as 'Tag' in findobj. Shouldn't it work?
  댓글 수: 1
Dishant Arora
Dishant Arora 2013년 7월 18일
It would also work.
h = findobj(SecondGui , 'type' , 'axes')
or the above statement will return handles to all the axes. h will be a vector.

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

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by