问题
I have this:
leg2=strcat('Max Degree :',num2str(adet(1,1)/ch(l)));
leg3=strcat('Min Degree :',num2str(adet(1,2)/ch(l)));
leg4=strcat('Max Request :',num2str(adet(1,3)/ch(l)));
leg5=strcat('Min Request :',num2str(adet(1,4)/ch(l)));
leg6=strcat('Max Priority :',num2str(adet(1,5)/ch(l)));
leg7=strcat('Random :',num2str(adet(1,6)/ch(l)));
leg8=strcat('AICS :',num2str(adet(1,7)/ch(l)));
legend(leg2,leg3,leg4,leg5,leg6,leg7,leg8,'Location','SouthWest');
Here, adet(1,1)/ch(l)
is a number between 0 and 1. And sometimes it becomes something like 0.01666667
. I'd like to set a precision for it to make it something like "0.02".
I can do it with disp()
function with the format bank
. But I don't know how to apply it in a plot. and sorry for bad english.
回答1:
Use a format specifier in num2str (within the legend
statement):
>> num2str(pi) %// default
ans =
3.1416
>> num2str(pi, '%.2f') %// two decimal figures
ans =
3.14
来源:https://stackoverflow.com/questions/29103531/setting-precision-in-legend-notation-in-matlab