Please how to give different color for each plot for this case
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Dyuman Joshi
2022-8-9
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!