Index exceeds the number of array elements. Index must not exceed 1.

조회 수: 1 (최근 30일)
Chacha Ankush
Chacha Ankush 2021년 10월 20일
답변: Richard Stephens 2021년 10월 20일
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');

답변 (1개)

Richard Stephens
Richard Stephens 2021년 10월 20일
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by