I am working on a plot, with labels. Two questions: (1) how can I reduce the label to only 2 dp ?? and (2) how can I change the color of the label to match the color of the plot to which the label refers (i.e., 'r', 'g', 'b', or 'magenta') ?? Thanks
2 views (last 30 days)
Show older comments
%%Plotting Angular Velocity (rad/s)
TimeAV=Time1(ip-25:ip+50);
AngVelAVC=AngVelC(ip-25:ip+50)-mean(AngVelC(ip-50:ip-25));
AngVelAVS=AngVelS(ip-25:ip+50)-mean(AngVelS(ip-50:ip-25));
AngVelAVA=AngVelA(ip-25:ip+50)-mean(AngVelA(ip-50:ip-25));
AngVelAVM=AngVelM(ip-25:ip+50)-mean(AngVelM(ip-50:ip-25));
figname = sprintf('Analog-AngVel-%s',filename(1:end-4));
figure('name',sprintf('%s',figname));
plot(TimeAV,AngVelAVC,'r',TimeAV,AngVelAVS,'g',TimeAV,AngVelAVA,'b',TimeAV,AngVelAVM,'magenta')
imaxAVM=find(max(AngVelAVM)==AngVelAVM); text(TimeAV(imaxAVM),AngVelAVM(imaxAVM),[num2str(AngVelAVM(imaxAVM)),' rad/s'],'VerticalAlignment','top','HorizontalAlignment','right','FontSize',10);
iminAVC=find(min(AngVelAVC)==AngVelAVC); text(TimeAV(iminAVC),AngVelAVC(iminAVC),[num2str(AngVelAVC(iminAVC)),' rad/s'],'VerticalAlignment','top','HorizontalAlignment','right','FontSize',10);
iminAVS=find(min(AngVelAVS)==AngVelAVS); text(TimeAV(iminAVS),AngVelAVS(iminAVS),[num2str(AngVelAVS(iminAVS)),' rad/s'],'VerticalAlignment','bottom','HorizontalAlignment','right','FontSize',10);
iminAVA=find(min(AngVelAVA)==AngVelAVA); text(TimeAV(iminAVA),AngVelAVA(iminAVA),[num2str(AngVelAVA(iminAVA)),' rad/s'],'VerticalAlignment','top','HorizontalAlignment','left','FontSize',10);
title('Angular Velocity'); xlabel('Time(s)'); ylabel('AngVel(rad/s)'); legend('AngVel-Coronal','AngVel-Sagittal','AngVel-Axial','AngVel-Mag','location','best'); axis tight; grid on;
0 Comments
Answers (1)
Walter Roberson
on 13 Apr 2014
num2str() allows a format as the second argument. However, I find that in the majority of cases in which I would be tempted to call num2str() with two arguments, that sprintf() is a better alternative.
You can pass a 'Color' name/value pair into text() calls.
0 Comments
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!