我有这个:
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');
这里,adet(1,1)/ch(l)
是0到1之间的数字。有时它会变成0.01666667
。我想为其设置一个精度,使其类似于“0.02”。
我可以使用 disp()
函数和格式库
来完成此操作。但我不知道如何将其应用到情节中。抱歉英语不好。
最佳答案
在 num2str
中使用格式说明符(在legend
语句中):
>> num2str(pi) %// default
ans =
3.1416
>> num2str(pi, '%.2f') %// two decimal figures
ans =
3.14
关于matlab - 在matlab中设置图例符号的精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29103531/