How to make a legend print proper numbers

조회 수: 62 (최근 30일)
chong kai sheng
chong kai sheng 2020년 6월 4일
편집: Ameer Hamza 2020년 6월 4일
How do i get the legend to do i print r values of 0.05, 0.1 and 0.5 . I want them to be the same as 1 and 10
colourmap = [228 26 28; 55 126 184; 77 175 74; ...
152 78 163; 255 127 0]/255;
%variables
r = [0.05 0.1 0.5 1 10];
t = (0:0.01:100);
k = 15
B0 = 1;
%
for i = 1: length(r)
dBdt =@(t,B) (round(r(i)).*B).*(1-(B./k));
[t,B] = ode45(dBdt,t,B0);
figure(6);
loglog(t,B,'color',colourmap(i,:))
grid on;
hold on;
%loop for b >= 10
end
xlabel('Time');
ylabel('Bacteria growth');
title('B against t');
legend(cellstr(num2str(r','r = %d')),'location','northwest');
Here is the result of the graph

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 6월 4일
편집: Ameer Hamza 2020년 6월 4일
Try this
legend(num2str(r','r = %5.2f'),'location','northwest'); % cellstr is not required
%d is used for integer values. You need to use %f for floating point values.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by