Live Editor: Brace indexing changes Table to Struct

3 ビュー (過去 30 日間)
Kevin Laabs
Kevin Laabs 2022 年 12 月 15 日
コメント済み: Voss 2022 年 12 月 15 日
Hi guys,
I have a table (basicly imported from multiple .csv and combined them in .-annotation) with some doubles and some strings. Everything worked until I expanded on my code to do some analysis on the doubles of the table.
As soon as I use the brace indexing for the table (for example to get all the zeros in my rigth hand double data) or if I try to get the height of the table, the live editor breaks the table, converts it to a struct and refuses the {}-brace indexing. If I terminate my code before the indexing and use the exact same lines of codes that would follow in the live script (basically copy paste per line) in the command window, everything works as expected. The table stays as a table and the information can be processed with brace indexing.
So I have a table A with ~500 rows and 11 columns. column 1 and 4 are strings the rest are doubles.
If I use:
I get:
Brace indexing is not supported for variables of this type.
If I use it in the Command window (without executing it in the live Editor), it works as intended and the Table is untouched. If I try the line in the Command window after the line gets used in the live editor I get the same error message as in the live editor and I found that the table gets converted to a struct with 11 fields.
The conversion of the table to a struct also happens with:
Error using table2array (line 34)
Input argument must be a table.
Which results in a wrong result of test1=1 (instead of the expected ~500)
This happens in 2022b and 2021b...
Since I can't post most of the code and especially not the .csv files that generate the table in the first place, I am unsure how to troubleshoot this. Please guide me in what I can provide and how to troubleshoot this here as best as possible.
Thanks in advance,
  3 件のコメント
Voss 2022 年 12 月 15 日
As Peter Perkins said, "You can certainly post something like the table you have."
Can you construct and post a simplified version of your code and data that appears to exhibit the same difference in behavior in the Command Window vs the Live Editor? (Maybe in attempting to do that, you'll discover what the problem is.)


回答 (2 件)

Voss 2022 年 12 月 15 日
Your table is A, but all of the code we can see here involves A.all. Shouldn't you be doing, for instance:
instead of:

Peter Perkins
Peter Perkins 2022 年 12 月 15 日
You can certainly post something like the table you have.
In any case, if A is a table, then A.all is a variable in that table. Maybe a double column vector, maybe something else. A(:,5:end) is the 5th though end'th value of the all variable in A. There's no reason to call table2array on it, because it is not a table.
A.all{i,5:end} tries to do cell indexing on A.all. if A.all is a double, that isn't going to work.
I recommend that you take a look at the table doc.


Help Center および File ExchangeCharacters and Strings についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by