Array Index .. values ERROR

1 回表示 (過去 30 日間)
Peter Vella
Peter Vella 2019 年 8 月 16 日
コメント済み: Walter Roberson 2019 年 8 月 19 日
I am p/ time student and I have a main file with supporting functions which is giving me the error "Array indices must be positive integers or logical values. (Quite new to MATLAB)
(Have attached the files which have been found in an MSc thesis, which I intend to modify to suit my needs. But as a starter I need to get these working ...)
1) LOADER needs to run first based on the xlsx file (which looks to be working well)
2) Hence TESV should run. When it does it is finding a problem with GETMASS ...
Thanks if anyone can help.
  4 件のコメント
Stephen23
Stephen23 2019 年 8 月 16 日
編集済み: Stephen23 2019 年 8 月 16 日
@Peter Vella: when the error occurs, what size is tempsCol, and what values does it have?
The debugging tools will help you, e.g. dbstop if error
Peter Vella
Peter Vella 2019 年 8 月 16 日
>> size tempsCol
ans =
1 8
>> size massCol
ans =
1 7
There certainly is a mismatch but I cannot sort it out yet ..

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

回答 (1 件)

Subhadeep Koley
Subhadeep Koley 2019 年 8 月 19 日
Hi Peter,
By setting breakpoint on line 13 of the live script GETMASS.mlx I can see that the elements of the array tempsCol is not integers instead they are double.
tempsCol.PNG
Therefore, elements of tempsCol cannot be used as array indexes.
Also, RHO_HTF is a variable of size (1×55) whereas tempsCol is (1×20). Therefore, even if tempsCol were of integer / logical class it would give “Index exceeds the number of array elements (55)” error.
Therefore, Some changes in your logic is required so that the tempsCol elements become integers or logical values of size 1×55.
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 8 月 19 日
Though if tempsCol were logical, it could be of any length provided that it does not have any true values in any position past the end of the array it is indexing. A 1 x 20 logical would be valid to index a 1 x 55 array: positions 23 to end would be treated as false .
But this quibble about how logical indices operate is not likely to be relevant. It is relevant, though, that integer indices around 75-ish are past the end of a 1 x 55 array.

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

カテゴリ

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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by