Assign elements in multidimensional struct to 2D array

I have a 1xN multidimenstional struct, where each entry contains data of size 1xM.
for ii=1:5, C(ii).pts = rand(1,3); end
I would like an elegant way to get an NxM array as a concatinated output of the struct. Is this possible?
% Returns of size 1xMN
[C.pts]
% Will not run but get something like this of size NxM
[c.pts']
Relevant questions:
https://www.mathworks.com/matlabcentral/answers/7155-elegant-way-to-extract-part-of-a-structure-as-an-array

2 件のコメント

Stephen23
Stephen23 2022 年 9 月 14 日
編集済み: Stephen23 2022 年 9 月 14 日
You are not limited to only using square brackets for concatenation, you can use a comma-separated list with any operator or function that accepts those input arrays:
cat(1,C.pts)
vertcat(C.pts)
Collin
Collin 2022 年 9 月 14 日
This was exactly what I was looking for, thank you

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

 採用された回答

James Tursa
James Tursa 2022 年 9 月 14 日
編集済み: James Tursa 2022 年 9 月 14 日

1 投票

You can use the vercat( ) function to force the comma-separated-list generated by C.pts to stack vertically:
for ii=1:5, C(ii).pts = rand(1,3); end
vertcat(C.pts)
ans = 5×3
0.5913 0.0767 0.8684 0.9742 0.6071 0.1215 0.7279 0.3782 0.8562 0.0783 0.6597 0.9261 0.9670 0.2707 0.2494

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

タグ

質問済み:

2022 年 9 月 14 日

コメント済み:

2022 年 9 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by