using hold on function in step response with subplot

I am trying to plot step reponse and impulse reponse of a sys in a single plot,using suplot and lengend, but i too have different values of z to be ploted (means i am using hold on fun). when i try to use subplot with the created code it's plotting for only one value of z, but i want such that all the three values of z has to plotted for both the step and impulse function in subplot, I apperciate your help.
s=tf('s');
z=[3 6 12];
hold on
for i=1:3
zc=z(i);
g=(15/zc)*((s+zc)/(s^2+3*s+15));
subplot(2,1,1)
step(g)
subplot(2,1,2)
impulse(g)
end
legend('z = 3','z = 6','z = 12')

 Réponse acceptée

Walter Roberson
Walter Roberson le 25 Fév 2019

2 votes

Code attached. Mostly it was moving the hold()

1 commentaire

BALA GUGA GOPAL S
BALA GUGA GOPAL S le 25 Fév 2019
Modifié(e) : BALA GUGA GOPAL S le 25 Fév 2019
Thank you for your help, It got worked with your method.

Connectez-vous pour commenter.

Plus de réponses (1)

You just have to a little bit of modification in your code. I have done it and it is producing the following result
untitled.png
I hope that you wanted the above output. The modified code is given below
s=tf('s');
z=[3 6 12];
for i=1:3
zc=z(i);
g=(15/zc)*((s+zc)/(s^2+3*s+15));
subplot(2,2,i)
step(g)
hold on
impulse(g)
legend('z = 3','z = 6')
end

6 commentaires

Thank for your help. but when i try to plot for all the values of z(i) in single plot only values for z=3,6 is being only plotted.for both impulse and step. But i want something like this combined in a single plot using subplots for step and impulse. I apperciate your help in regard this.2.jpg
1.jpg
Do you want step response for z = 3,6 and 12 in one subplot and impulse response for z = 3,6 and 12 in another subplot?
Yes sir, the exact way you asked for, step response for z = 3,6 and 12 in one subplot and impulse response for z = 3,6 and 12 in another subplot. any help with that in the above code will be helpfull, i have tried lot ways.
Thank you with little bit more of change in the code you gave it, it worked. Answer script is given by Mr.Walter attached down. Thank for your help
You can try the following code
s=tf('s');
z=[3 6 12];
subplot(2,1,1)
hold on
for i=1:3
zc=z(i);
g=(15/zc)*((s+zc)/(s^2+3*s+15));
step(g)
end
legend('z = 3','z = 6','z = 12')
subplot(2,1,2)
hold on
for i=1:3
zc=z(i);
g=(15/zc)*((s+zc)/(s^2+3*s+15));
impulse(g)
end
legend('z = 3','z = 6','z = 12')
The output for this code is shown below
untitled.png
thank you this too got worked out.Thank you for your help.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by