Array indices must be positive or logical values.

1 回表示 (過去 30 日間)
Iman Fitri  Ismail
Iman Fitri Ismail 2020 年 11 月 28 日
コメント済み: Iman Fitri Ismail 2020 年 11 月 28 日
Hi,
I have a problem in converting my Fortran77 codes to MATLAB. Here are the equation of arrays that worked in FORTRAN77 but somehow showing "Array indices must be positive integers or logical values".
IDIM = 3000;
D = [-1:IDIM+2];
U = [-1:IDIM+2];
P = [-1:IDIM+2];
if IBCLEF == 0
D(0) = D(1);
U(0) = U(1);
P(0) = P(1);
else
D(0) = D(1);
U(0) = -U(1);
P(0) = P(1);
end
if IBRIGH == 0
D(CELLS+1) = D(CELLS);
U(CELLS+1) = U(CELLS);
P(CELLS+1) = P(CELLS);
else
D(CELLS+1) = D(CELLS);
U(CELLS+1) = -U(CELLS);
P(CELLS+1) = P(CELLS);
end
It will give me
Array indices must be positive integers or logical values.
Error in (line 6)
D(0)=D(1);
I have been trying to look for solutions, but somehow I couldn't figure out the problems with setting up the array values.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 28 日
In MATLAB, the index of an array starts from 1 (as compared to many other languages where it starts from 0). Therefore, these lines should be something like this
D(1) = D(2);
  1 件のコメント
Iman Fitri  Ismail
Iman Fitri Ismail 2020 年 11 月 28 日
Thank you very much, it works!

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

その他の回答 (0 件)

カテゴリ

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