MATLAB Answers

how i can convert struct to matrix

조회 수: 132(최근 30일)
mathematics
mathematics 20 Oct 2019
답변: Image Analyst 20 Oct 2019
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.

  댓글 수: 0

로그인 to comment.

답변(2개)

YT
YT 20 Oct 2019
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 ).

  댓글 수: 0

로그인 to comment.


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

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

제품


릴리스

R2019a

Translated by