Indexing of a size() object

7 ビュー (過去 30 日間)
Adrian Valente
Adrian Valente 2020 年 11 月 27 日
編集済み: Stephen23 2020 年 11 月 27 日
Hello,
If I have an array named arr, and run the following:
size(arr)(1)
then I get an error: "Indexing with parentheses '()' must appear as the last operation of a valid indexing expression."
However when adding an intermediate step:
s = size(arr);
s(1)
then everything runs as expected. So I don't have a practical problem to solve here, but was curious to know more about the reasons for that behavior, and when indexing should not be used.
  1 件のコメント
Stephen23
Stephen23 2020 年 11 月 27 日
編集済み: Stephen23 2020 年 11 月 27 日
Note that
size(arr,1)
would be the MATLAB way to measure the first dimension of an array.

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 27 日
編集済み: Ameer Hamza 2020 年 11 月 27 日
Unlink some other languages, such a chain of indexing is not supported in MATLAB. You can find the discussion on this issue on the following links
I guess one of the main reasons it is still not supported is because of the ambiguity between the function call and indexing. Both use pranthesis (). If Mathworks make the decision to support this now, it can make the program slow and make it difficult for the JIT compiler to improve the speed.

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by