How to extract a field from a structure?
조회 수: 159 (최근 30일)
이전 댓글 표시
I want to extract an entire field from structures with multiple fields and store it in a vector:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/953980/image.png)
vector = S.(sample)
only returns me row 1
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/953985/image.png)
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!