Subscript indices must either be real positive integers or logicals.

1 回表示 (過去 30 日間)
Lucas Vacus
Lucas Vacus 2019 年 8 月 17 日
編集済み: KALYAN ACHARJYA 2019 年 8 月 17 日
x=[1 2 3 4];
h=[1 2 3];
m=length(x);
n=length(h);
OP_len=m+n-1;
less=OP_len-n;
Abs=h;
for Kk=1:less
Abs=[Abs,0];
end
Y=Abs.';
for jj=1:m
temp=Abs(OP_len-1);
for kk=OP_len:-1:1
Abs(kk)=Abs(Kk-1);
end
Abs(0)=temp;
Y=[Y,Abs.'];
end
Why I am getting "Subscript indices must either be real positive integers or logicals." Error
Error in LinConvolution (line 20)
Abs(Kk)=Abs(Kk-1);

回答 (2 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 8 月 17 日
編集済み: KALYAN ACHARJYA 2019 年 8 月 17 日
Abs(1)=temp;
In Matlab indexing start from 1, not zero
Hence
Allowed
A(1), A(2), A(3),....
Not Allowed
A(0), A(-1), A(-2),....etc

the cyclist
the cyclist 2019 年 8 月 17 日
Unlike some other programming languages (e.g. python), MATLAB has 1-based indexing. The first element of the array A would be referenced as A(1), not A(0). So, if you try to access A(0), you will get that error message.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by