Filter löschen
Filter löschen

Plotting Step Responses with For Loops

7 Ansichten (letzte 30 Tage)
N/A
N/A am 24 Jan. 2015
Kommentiert: N/A am 25 Jan. 2015
Hi, I have a problem with the plot command in regards to plotting step responses in for loops. I've searched everywhere and cannot find what I'm looking for. I am hoping someone can help me. Here's my problem:
I need to plot a simple step response over a series of different time constants. It's a first order system with time constant ranging from 35 over multiples of 5 to 60, and it begins at 25 and ends at 100 (it's a temperature problem).
Here's my code:
>> for tau=35:5:60,
sys=tf([75],[tau 1]);
y=25+step(sys);
plot(y)
hold on
end
And with that, all I get is one curve using the last tau of 60. And that's the value MATLAB stores even though I told it to keep 35-->60. If I use just "step(sys)", I get all my curves. I think it has something to do with the plot command. Any help is appreciated--thank you in advance!!

Akzeptierte Antwort

Rick Rosson
Rick Rosson am 25 Jan. 2015
figure;
axes;
hold on;
for tau = 35:5:60
sys = tf([75],[tau 1]);
[y,t] = step(sys);
plot(t,25+y);
end
  1 Kommentar
N/A
N/A am 25 Jan. 2015
Yes! Thank you so much! I wonder why the loop didn't hold for my code? Because if I would just directly use
step(sys)
hold on
end
...everything works (except the 25 increase at the beginning). Either way, now it works, so thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by