필터 지우기
필터 지우기

How to share plot from one GUI to another using setappdata / getappdata approach?

조회 수: 2 (최근 30일)
Shoaib Bilal
Shoaib Bilal 2019년 3월 11일
댓글: Jan 2019년 3월 13일
Hi, I’m trying to pass plot / Image from GUI1 to GUI2 but unable to do this. I prefer setappdata / getappdata approach. I’m creating GUIs using GUIDE.
This is the code which I'm writing in GUI1:
IM=double(getimage(handles.axes1))
setappdata(0,'IM',IM);
GUI2 % calling GUI2
And this is the code in GUI2:
IM=getappdata(0,'IM')
axes(handles.axes1)
imshow(IM)
But in command window it shows:
>> GUI1
IM =
[]
IM =
[]
And in GUI2 I'm not able to get the plot.
I've searched it a lot on youtube also but I'm not getting the solution. So if anyone knows then kindly share the solution of this problem as soon as possible.
  댓글 수: 16
Adam
Adam 2019년 3월 13일
You would be better off, in general, to put your plotting code into a function, taking the arguments it needs to create the plot and then just pass this data around to wherever you want (e.g. the 2nd GUI) and call your plotting function on the 2nd GUI rather than moving and copying GUI objects themselves around.
Jan
Jan 2019년 3월 13일
@Shoaib Bilal: "Can you please write the proper code which i have to add and also tell where I have to add that code?" - Sorry, this is not possible. I cannot guess, what your full current code is. You have posted a small piece of it only. The code I have posted in my answer is proper already and it has to be inserted in the code, which you have called "GUI2 Pushback button".

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

답변 (1개)

Jan
Jan 2019년 3월 12일
편집: Jan 2019년 3월 12일
To avoid troubles, define the Parent property when drawing in a GUI:
...
Ax = handles.axes1;
plot(Ax, x1,y1,'b','LineWidth',2)
grid(Ax, 'on');
hold(Ax, 'on');
plot(Ax, x1,-y1,'b','LineWidth',2)
line(Ax, [x1(1) x1(1)],[y1(1) -y1(1)],'LineWidth',2,'Color',[0 0 1])
line(Ax, [x1(noc) x1(noc)],[y1(noc) -y1(noc)],'LineWidth',2,'Color',[0 0 1])
xlim(Ax, [-0.1 0.7]);
ylim(Ax, [-0.2 0.2]);
...
You need to call hold on once only.
If the tag of the GUI is 'GUI1' , use this to copy the axes1 of the first GUI to the 2nd GUI:
function AXZ_Callback(ObjectH, EventData, handles)
GUI1H = findobj(allchild(groot), 'flat', 'Figure', 'Tag', 'GUI1');
GUI1handles = guidata(GUI1H);
GUI2H = ancestor(ObjectH, 'figure'); % Or the corresponding handles field
copyobj(GUI1handles.axes1, GUI2H);
end

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by