Array indices must be positive integers or logical values?

1 回表示 (過去 30 日間)
Chinni Sai Ram
Chinni Sai Ram 2022 年 8 月 6 日
回答済み: John D'Errico 2022 年 8 月 6 日
X=[1 2 3 4 5];for i=0:length(X) if mod(i,2)==0 f(i)=X(i); end end
  1 件のコメント
Chinni Sai Ram
Chinni Sai Ram 2022 年 8 月 6 日
Showing Array indices must be positive integers or logical values. where I committed error? Please tell me.

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

回答 (1 件)

John D'Errico
John D'Errico 2022 年 8 月 6 日
MATLAB does not allow an index of 0. The FIRST element of an array or vector is indexed as x(1).
In your loop, what was the range of the index i? You said
for i = 0:length(X)
So what does i start out as? (HINT: 0)
Now go back and read the first line I wrote.

カテゴリ

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