Change colors of lines from an iterated plot function.

I'm plotting different values of beta using a for loop. But the color is the same for each line plotted. How can I also iterate a color change? This is the code in the file that will call the function.
%%Lab 2_1
b = [6,30,60,400];
type susp
for n = 1:4;
susp(1,900,b(n))
hold on
end
hold off
This is the function that I am calling.
function susp(M, k, beta)
% SUSP Simulate suspension
% susp(M, k, beta)
%
% Produces a plot of the displacement of the suspension, x,
% as a function of time, given parameters
% M (mass), k (spring constant) and beta (damping)
t = -1:0.001:2;
f = u(t);
F=k;
sys = tf(F/M, [1 beta/M k/M]);
y = lsim(sys, f, t);
plot (t, f, 'b', t, y,'r', 'lineWidth',2);
ylim([-0.5 1.5]);
grid on;
return

답변 (1개)

Chad Greene
Chad Greene 2015년 9월 13일
The problem is the 'b' and the 'r' in the plot function. They're setting all lines to blue or red. Try this:
plot(t,f,t,y,'lineWidth',2);

카테고리

도움말 센터File Exchange에서 Animation에 대해 자세히 알아보기

태그

질문:

2015년 9월 13일

답변:

2015년 9월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by