Expected one output from a curly brace or dot indexing expression but there were 2 results

130 ビュー (過去 30 日間)
I am using a code to combine some common information from two data structure arrays. The code gives the below error:
"Expected one output from a curly brace or dot indexing expression, but there were 2 results" in line 101 of the code.
I am a newbie and not very strong in MATLAB. I appreciate if some one can help me solve this problem. I have attached the codes and the structures here in.

採用された回答

Stephen23
Stephen23 2021 年 1 月 8 日
編集済み: Stephen23 2021 年 12 月 27 日
For your code to work the index tn4 must be scalar, but the error message tells us that it is not.
Compare:
S(1).blah = 1:3;
S(2).blah = 5:7;
S(1).blah(1) % index into S is scalar
ans = 1
S(1:2).blah(1) % index into S is NOT scalar
Expected one output from a curly brace or dot indexing expression, but there were 2 results.
In both cases the indexing into S creates a comma-separated list (of one and two variables respectively):
The error occurs because the indexing at the end is ambiguous when applied to two or more variables of a comma-separated list, it is only applied without error when the comma-separated list returns exactly one array.
So you need to figure out:
  • if the assumption of only one index value for tn4 is appropriate or not,
  • how to handle the cases where zero, two or more indices are found (e.g. throw an error, or handle only one index, or special case handling, or use default data, or skip an iteration, etc.)
  2 件のコメント
Madura Meenakshi Ramamoorthi
Madura Meenakshi Ramamoorthi 2021 年 12 月 27 日
instead of S(1:2).blah(1) just try
S(1:2).blah
Stephen23
Stephen23 2021 年 12 月 27 日
@Madura Meenakshi Ramamoorthi: the OP originally uploaded code and data files which indicated that they wanted to index into the structure field array, not into the structure itself.

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

その他の回答 (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