Array indices must be positive integers or logical values MATLAB error

1 回表示 (過去 30 日間)
Lucas Larese De Santo
Lucas Larese De Santo 2020 年 5 月 10 日
Why do I keep getting an error "Array indices must be positive integers or logical values"?
m1=100; m2=50; k1=7410; k2=8230; b1=1430; b2=153;
A=[0 1 0 0;
-(k1+k2)/m1 -(b1+b2)/m1 k2/m1 b2/m1;
0 0 0 1;
k2/m2 b2/m2 -k2/m2 -b2/m2];
B=[0 0;
k1/m1 b1/m1
0 0;
0 0];
C=[1 0 0 0;
0 0 1 0;
k1/m1 b1/m1 0 0;
-k2/m2 -b2/m2 k2/m2 b2/m2];
D=[0 0;
0 0
k1/m1 b1/m1
0 0];
h0=0.05;
t0=1;
w=2*pi/t0;
t=0:0.01:4;
z0=h0*sin(w*t).*(0<=t & t<t0)
z0dot=h0*w*cos(w*t).*(0<=t & t<t0);
sys=ss(A,B,C,D);
lsim(sys,z0(t),t)
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 5 月 10 日
I notice you compute z0dot but you do not use it?

サインインしてコメントする。

回答 (1 件)

Toder
Toder 2020 年 5 月 10 日
z0(t) is causing the error. t is a vector of decimals, and you cannot use a decimal as an index. Indices must be positive integers, or logical values, as the error mentions.
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 5 月 10 日
My z0 is a 1x401 double
No, your sys has 2 inputs and 4 outputs, and 401 time points, so your z0 should be 401 x 2 . You should not be replmat() your existing z0: you should be defining pairs of inputs that you want the output state to be calculated for.
Lucas Larese De Santo
Lucas Larese De Santo 2020 年 5 月 10 日
Ok thank you. So what I could thereotically do is for my input for the lsim use [z0;z0dot] then? You also mention z0 should be a 401 x 2, why is that instead of a 2 x 401?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePassivity and Sector Bounds についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by