how i can convert struct to matrix

조회 수: 30 (최근 30일)
mathematics
mathematics 2019년 10월 20일
답변: Image Analyst 2019년 10월 20일
Hello Dear Matlab users,
Is there any way to convert str to matrix form? I want to get all values of different fields with its subvalues. Thank you for the help.Attached my code.

답변 (2개)

YT
YT 2019년 10월 20일
You could, for example, create a cell array:
C = {};
C{1,1} = s(1).f1;
C{1,2} = s(1).f2;
C{2,1} = s(2).f1;
C{2,2} = s(2).f2;
I suggest making a for-loop, but I hope you get the idea.
BTW there's also a build-in function struct2cell which does this for you ( except it creates a multidimensional array ).

Image Analyst
Image Analyst 2019년 10월 20일
You'd do this:
st = load('mat_str.mat')
f1 = vertcat(st.s.f1)
f2 = cat(3, st.s.f2)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by