Extracting data from struct as array
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi, I have a following structure:
S(1).a = 1:10;
S(2).a = 11:20;
S(3).a = 21:30;
I want the output in the following format:
y = [1:10; 11:20; 21:30];
Using [S(1:3).a] concatenates it in a single direction. Is there a better way (other than for loop) to extract the data in the requisite format?
Thank you,
Rashi
댓글 수: 0
채택된 답변
추가 답변 (1개)
Ganesh
2024년 6월 13일
You can use "vertcat()" for using the same. Refer to the following code:
% Your structure
S(1).a = 1:10;
S(2).a = 11:20;
S(3).a = 21:30;
% Extracting and concatenating
y = vertcat(S.a); % This works directly because of how MATLAB handles struct arrays
y
For more information on the function "vertcat()", refer to the following documentation:
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!