Please how to give different color for each plot for this case

조회 수: 2 (최근 30일)
Abdelkader Hd
Abdelkader Hd 2022년 8월 9일
댓글: Dyuman Joshi 2022년 8월 11일
x = [-2:0.1:2];
a = [.5, 1, 1.3, 1.95];
figure;
for i=1:length(a)
z = x.*(a(i)-x.^2);
plot(x,z);hold on;
end

답변 (1개)

Dyuman Joshi
Dyuman Joshi 2022년 8월 9일
One way is to use rand. Colors here will be choosen randomly
x = [-2:0.1:2];
a = [.5, 1, 1.3, 1.95];
figure;
for i=1:length(a)
z = x.*(a(i)-x.^2);
plot(x,z,'Color', rand(1,3))
hold on;
end
Another way is to use binary vectors -
%this works here as we only 4 graphs to plot
%there are only 8 binary triplets available
x = [-2:0.1:2];
a = [.5, 1, 1.3, 1.95];
figure;
for i=1:length(a)
z = x.*(a(i)-x.^2);
plot(x,z,'Color', dec2bin(i,3)-'0')
hold on;
end
  댓글 수: 4
Abdelkader Hd
Abdelkader Hd 2022년 8월 10일
Dear @Dyuman Joshi please if you have idea, I want the command to choose the color of the line and also the type of line (dashed line, dashed ...) and line width.
Thank you

댓글을 달려면 로그인하십시오.

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by