Array indices must be positive integers

6 ビュー (過去 30 日間)
Cis
Cis 2025 年 2 月 6 日
回答済み: KSSV 2025 年 2 月 6 日
I keep getting the error that my array indices are wrong. This for loop is nested inside of another for loop and it is fine the first time. However the second time I get the error. I have tried different things but I just don't see my mistake anymore. Could you please help me?
***EDIT***: Found te error, used Ts twice as a variable!

回答 (1 件)

KSSV
KSSV 2025 年 2 月 6 日
The error is clear......your indices are either negative or zeros double. When you are indexing, the indices should be either logical class (0,1) or positive integers.
Example:
A = [1 5 pi 2*pi cosd(90)] ;
A(1) % No error
A(-1) % error, becuase index is negative
A(0) % error becuase index is zero
idx = A > 1 ; % logical
A(idx) % no error, as idx is logical.
Int he same whay, use debuggig and check why the indices are neagtive.

カテゴリ

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

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by