필터 지우기
필터 지우기

Converting a vector of structs to just one struct (vectorizing)

조회 수: 2 (최근 30일)
Emanuel
Emanuel 2022년 7월 18일
댓글: Stephen23 2022년 7월 18일
So i have this struct and in it there are, for example, 402 1x1 structs with the same variables (not same values of course).
What i need is to all that structs to become just one (or none at all, just the variables). In other words, if i have 402 user variables in the shape
[1 2 3], i want to make a 402x3 variable.

채택된 답변

Jan
Jan 2022년 7월 18일
X = cat(1, S(:).FieldName);
% Or shorter:
X = cat(1, S.FieldName);
% Example:
S(1).FieldName = [1,2,3];
S(2).FieldName = [4,5,6];
X = cat(1, S.FieldName)
X = 2×3
1 2 3 4 5 6
  댓글 수: 3
Jan
Jan 2022년 7월 18일
I cannot know, what "I have 402 1x1 structs" exactly means. Is this a struct array or are they 402 different variables (which would be a very bad idea)?
I've showed how to extract the data of a field stored in a struct array. How to apply it to your data would get clear, if you explain exactly, what kind of data you have. Prefer to post some code which creates example data.
Emanuel
Emanuel 2022년 7월 18일
It is a struct array, yes.
After your example i've tried a more low-level approach of extracting the data and it worked as i expected. Thanks for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by