How to extract a field from a structure?
188 ビュー (過去 30 日間)
古いコメントを表示
I want to extract an entire field from structures with multiple fields and store it in a vector:
vector = S.(sample)
only returns me row 1
vector = S(2).data
This would return me the second position but when I try to extract all the data
vector = S.data
or
vector = S(:).data
I still get only 24x250x50 double, and not all the data column.
Thank you!
採用された回答
Voss
2022 年 4 月 5 日
% making a struct array with two fields:
S = struct('sample',num2cell(1:10),'info',sprintfc('information_%d',1:10))
% get the 'sample' field from each element of S, put them in a vector:
vector = [S.sample]
% get the 'info' field from each element of S, put them in a cell array:
cell_array = {S.info}
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!