how i can convert struct to matrix
16 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
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 ).
0 个评论
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!