how to put function's out put plot in Guide axes

Hi all
I have a function which has a figure as output . now I'm trying to use this function as part of my GUI and i want to put this figure in axes of my GUI.thanks for any solotion.

 채택된 답변

Adam Danz
Adam Danz 2018년 11월 16일
Suppose your function produces the following figure
figure;
axHand = axes;
hold(axHand, 'on')
plot(rand(10));
plot(rand(10), 'o')
and your GUI figure axis is named 'guiAxisHandle'. To copy everything in 'axHand' to 'guiAxisHandle',
copyobj(axHand.Children, guiAxisHandle)
Now you can delete the orginal figure.
delete(axHand.Parent)

댓글 수: 4

thanks
but let me explain more :
i have this function
function PlotSolution(X, sol)
% Cluster Centers
m = sol.Position;
k = size(m,1);
% Cluster Indices
ind = sol.Out.ind;
Colors = hsv(k);
for j=1:k
Xj = X(ind==j,:);
plot(Xj(:,1),Xj(:,2),'x','LineWidth',1,'Color',Colors(j,:));
hold on;
end
plot(m(:,1),m(:,2),'ok','LineWidth',2,'MarkerSize',12);
hold off;
grid on;
end
which it is in another for loop and update countiniously.
so deleting figure may be not good choice here.
Adam Danz
Adam Danz 2018년 11월 16일
편집: Adam Danz 2018년 11월 16일
In that case, plot directly to the GUI figure (which is the better solution anyway). If your GUI axis is named guiAxisHandle,
plot(guiAxisHandle, Xj(:,1),Xj(:,2), ...)
plot(guiAxisHandle, m(:,1),m(:,2), ...)
But first you'll need to get the handle to your gui axis. To do that, use guidata() and the handle to your GUI.
H = guidata(GUIhandle);
guiAxisHandle = H.axis1 % I don't know what your axis handled is named
thanks again dear adam
I dont know why but the result in axis is just the second plot and nothing plotted for the first plot(which is in the loop)
I don't know what axis you're referring to and I don't know what the first and second plot are nor do I know what loop your're talking about. I assume you made some changes to your code so 1) could you share the updated code and 2) try to explain what you'd like it to do and 3) what's wrong with it?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

질문:

2018년 11월 16일

댓글:

2018년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by