Transpose a structure with named fields ?
조회 수: 74 (최근 30일)
이전 댓글 표시
I have a struct that looks like this:
i.g. labeled fields
I have been trying to apply this example:
% Fake data
s(1).f = rand(1,100);
s(2).f = rand(1,100);
s(3).f = rand(1,100);
c = arrayfun(@(x)x.f.', s, 'UniformOutput', 0);
s = cell2struct(c, 'f');
but I think it doesn't work becuase I have labeled feilds.
Any ideas?
댓글 수: 1
Stephen23
2020년 6월 24일
편집: Stephen23
2020년 6월 24일
"Any ideas?"
Your screenshot shows a scalar structure with multiple fields.
Your example code has a non-scalar structure with one field.
It is not clear how that example would apply to the scalar structure shown in your screenshot.
You could use structfun like Mehmed Saad showed, or simply loop over the fieldnames:
채택된 답변
Mehmed Saad
2020년 6월 24일
if all of them are scalar then this will work
s_mod=structfun(@transpose,s,'UniformOutput',false)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!