Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Plot with markers defined

1 回表示 (過去 30 日間)
Ronald Niwamanya
Ronald Niwamanya 2020 年 9 月 11 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am plotting the same function for different parameters. I dont want to repeat writing the functions so I use the for loop.
How can i define markers so that each line/curve (attached) has a different marker?.
Below is the sample code.
clear, clc, close all
x = (-2:0.4:2);
for a=[2,3,4]
if a == 2
power = 'Power=2';
elseif a == 3
power = 'Power=3';
elseif a == 4
power = 'Power=4';
else
error('not-supported.')
end
y = x.^a;
plot(x,y,'-s','LineWidth',2,'DisplayName',sprintf(power));
hold on
grid on
legend
  2 件のコメント
KSSV
KSSV 2020 年 9 月 11 日
What exactly you want to do?
Ronald Niwamanya
Ronald Niwamanya 2020 年 9 月 11 日
Hi. I need to plot the above diagram but using different markers for each line. Is there a way I can do it so that I can just keep changing the parameter a and seeing the results?

回答 (1 件)

KSSV
KSSV 2020 年 9 月 11 日
編集済み: KSSV 2020 年 9 月 11 日
x = -2:0.4:2;
for a= [2 3 4] ;
if a == 2
M = {'-*r'} ;
elseif a == 3
M = {'-db'} ;
elseif a == 4
M = {'-ok'} ;
else
error('not-supported.')
end
y = x.^a;
plot(x,y,M);
hold on
grid on
end
legend
OR
clear, clc, close all
x = -2:0.4:2;
a= [2 3 4] ;
m = length(x) ;
n = length(a) ;
y = zeros(m,n) ;
for i = 1:n
y(:,i) = x.^a(i) ;
end
plot(x,y) ;
legend

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by