Replace a subplot title on a figure from another function in appdesigner
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jason
am 17 Jun. 2020
Kommentiert: Jason
am 18 Jun. 2020
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
Akzeptierte Antwort
Prince Sachdeva
am 18 Jun. 2020
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).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!