Access value in cell arrays
古いコメントを表示
A{1,1}.str = 1;
A{2,1}.str = 2;
... (so on)
A{10,1}.str = 10;
Can I say:
B = A{:,1}.str;
so that:
B=[1 2 3 4 5 6 7 8 9 10];
Thanks very much
2 件のコメント
per isakson
2013 年 6 月 29 日
Is A supposed to be a cell arrays of structures?
A field named "str" holding a numerical value isn't that confusing?
TN
2013 年 6 月 29 日
採用された回答
その他の回答 (2 件)
No. You can do this instead
A(1).str = 1;
A(2).str = 2;
...
A(10).str = 10;
B=[A(:).str]
3 件のコメント
TN
2013 年 6 月 29 日
Matt J
2013 年 6 月 29 日
It would not make sense to hold structures having the same fields inside cells. It just makes them harder to get to (as you've discovered).
per isakson
2013 年 6 月 29 日
編集済み: per isakson
2013 年 6 月 29 日
I agree.
However, for some reason the cell array may contain structures with only some fields in common.
James Tursa
2013 年 6 月 29 日
Another variation:
x = [A{:,1}];
B = [x.str];
カテゴリ
ヘルプ センター および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!