Change colors of lines from an iterated plot function.
Show older comments
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
Answers (1)
Chad Greene
on 13 Sep 2015
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);
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!