フィルターのクリア

How do i have a plot automatically allocate colours to lines and label them in a legend

3 ビュー (過去 30 日間)
Seb apple
Seb apple 2020 年 8 月 12 日
編集済み: VBBV 2020 年 8 月 13 日
can anyone help me as the code below i cannot seem to get matlab to automatically allocate each new valu for r to have a different colour. it either gives all new iterations the same colour or sometimes i have it vary each interation of n with a new colour which is not what i am looking for. please help
for n=1:0.1:2
for r=0:0.1:1
y=(n^2)*(2*r);
plot(n,r,'Linewidth',3.5)
hold on
legend({'0','0.1','0.2','0.3','0.4','0.5','0.6','0.7','0.8','0.9','1'})
xlabel('x')
ylabel('y')
set(gca,'fontsize',12,'FontName', 'Times')
end
end

採用された回答

VBBV
VBBV 2020 年 8 月 13 日
編集済み: VBBV 2020 年 8 月 13 日
The equation y=(n^2)*(2*r); needs to be function of variables otherthan n and r
In your program n and r are used iteration counters which are in decimal increments.
MATLAB does not allow decimal increment iterations
Try this code
% code modified
n = 1:0.1:2;
r = 0:0.1:1;
for i=1:length(n)
for j=1:length(r)
y(i,j)=(n(i)^2)*(2*r(j));
plot(y(:,j),'Linewidth',1.5);
hold on
legend({'0','0.1','0.2','0.3','0.4','0.5','0.6','0.7','0.8','0.9','1'});
xlabel('x');
ylabel('y');
set(gca,'fontsize',12,'FontName', 'Times');
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by