Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error when converting several arrays from struct to table

1 回表示 (過去 30 日間)
Espen Mikkelsen
Espen Mikkelsen 2018 年 4 月 9 日
閉鎖済み: Espen Mikkelsen 2018 年 4 月 12 日
Im trying to convert some arrays called var1, var2, var3 etc.in a struct variable to table. I have used struct2table like this:
struct2table(out.var1,out.var2,out.var3);
When I do that, I get following message:
"S must be a scalar structure, or a structure array with one column or one row".
What is the reason for that?

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 9 日
You say that you are converting those arrays, but what kinds of arrays are they? struct2table() requires that the first argument be a scalar structure or a structure vector, and that the arguments after that are name/value pairs.
I suspect you want
array2table(out.var1, out.var2, out.var3, 'VariableNames', {'var1', 'var2', 'var3'})
or more likely
array2table(out.var1(:), out.var2(:), out.var3(:), 'VariableNames', {'var1', 'var2', 'var3'})
  2 件のコメント
Peter Perkins
Peter Perkins 2018 年 4 月 11 日
Walter, array2table takes just one array. I think you were thinking of
table(out.var1, out.var2, out.var3, ...)
But I think maybe just
struct2table(out)
is what's needed.
Walter Roberson
Walter Roberson 2018 年 4 月 11 日
Ah, good catch
array2table([out.var1(:), out.var2(:), out.var3(:)], 'VariableNames', {'var1', 'var2', 'var3'})

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by