필터 지우기
필터 지우기

Replace a subplot title on a figure from another function in appdesigner

조회 수: 3 (최근 30일)
Hello, In appdesigner I have created an image on a subplot in a figure:
f1=figure('position',pos);
s1=subplot(1,3,1)
Im using a roi.ellipse object with an event listener, to allow the user to move and resize the ellipse.(all works fine)
h = images.roi.Ellipse(gca,'Center',[xpeak xpeak2],'Semiaxes',[1.699*fwhm/2 1.699*fwhm2/2],'Color','g','StripeColor','r','LineWidth',1); %1/e^2 = 1.699xfwhm
el=addlistener(h,'ROIMoved',@app.allevents);
what I want to do, is in the function "allevents" where I obtain the moved ellipse parameters, is to calculate the area and then replace the title of the sublot s1 with the area. But I'm having issues with changing the title.
function allevents(app,src,evt)
evname = evt.EventName;
switch(evname)
case{'MovingROI'}
disp(['ROI moving Current Center: ' mat2str(evt.CurrentCenter)]);
disp(['ROI moving Current SemiAxes: ' mat2str(evt.CurrentSemiAxes)]);
case{'ROIMoved'}
disp(['ROI moved Current Center: ' mat2str(evt.CurrentCenter)]);
disp(['ROI moved Current SemiAxes: ' mat2str(evt.CurrentSemiAxes)]);
a=evt.CurrentSemiAxes(1)
b=evt.CurrentSemiAxes(2)
area=pi*app.a*app.b
title(s1,['Area=',num2str(area,'%.1f')])
end
end
  댓글 수: 1
Jason
Jason 2020년 6월 17일
I have found this works:
h=get(gcf,'children')
title(h(3),['Area=',num2str(area,'%.1f')])
But Im not sure I shoud rely on the subplot(1,3,1) always being h(3).

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

채택된 답변

Prince Sachdeva
Prince Sachdeva 2020년 6월 18일
As per my understanding, you want to add a title to the sub plot after some pre-processing.
It seems to me that the below solution is working in the latest version:
f1=figure;
s1 = subplot(1, 3, 1)
title(s1,'Area')
The get(gcf, ‘children’) function returns the handles for the sub plots in the reverse order (i.e., the last subplot as the first handle), as you may have observed. So, you can reverse it again as shown below:
h=get(gcf,'children')
h=h(end:-1:1)
title(h(1),'G1')
title(h(2),'G2')
title(h(3),'G3')
Now, you can use h(1) for subplot(1, 3, 1).
  댓글 수: 1
Jason
Jason 2020년 6월 18일
Thankyou for confirming that with my subplot consisting of 3 subplots, the firat one drawn i.e. subplot (1,3,1) will ALWAYS be h(3). Thats all I wanted to confirm

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by