Change colors of lines from an iterated plot function.
Ältere Kommentare anzeigen
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
Antworten (1)
Chad Greene
am 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);
Kategorien
Mehr zu Animation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!