Index exceeds the number of array elements. Index must not exceed 1.
2 views (last 30 days)
Show older comments
close all;
>> clear all;
>> z=[0,0.1,0.2,0.4,0.6,0.7,0.8,0.9,1];
>> num=[0 0 75];
>> t=0:0.1:25;
>> u=ones(1,251);
>> r=t;
>> for i=1:1:9
den=[1 20*z(i) 75];
>> T=tf(num, den);
>> [y{i}]=lsim(T,r,t);
>> subplot(5,2,1);
>> plot (t,y{i},t,r);
>> title('time response of second order systemfor different values of zeta');
>> z=num2str(z(i));
>> end;
>> subplot(5,2,10);
>> plot(t,y{1},t,y{2},t,y{3},t,y{4},t,y{5},t,y{6},t,y{7},t,y{8},t,y{9});
>> axis([0 1 0 1]);
>> xlabel('time sec');
>> ylabel('amplitude');
>> title('time response for second second order systemfor different values of zeta');
>> legend ('z=0','z=0.1','z=0.2','z=0.4','z=0.6','z=0.7','z=0.8','z=0.9','z=1');
0 Comments
Answers (1)
Richard Stephens
on 20 Oct 2021
The line
z=num2str(z(i));
should be deleted: it overwrites z which becomes a single char.
It would be helpful if you submitted code without the ">>" by copying from the Command History window.
0 Comments
See Also
Categories
Find more on Matrix Indexing 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!