How to display structs only in a struct with fields?

조회 수: 2 (최근 30일)
Emily
Emily 2022년 4월 20일
댓글: Emily 2022년 4월 20일
I'm trying to display only the 1x1 struct portions and hide the character portions in a struct with fields.
aTable=struct2table(S);
disp(aTable);
  댓글 수: 2
Rik
Rik 2022년 4월 20일
Do you have an example of what kind of output you want? Can you provide a small example struct with the intended output?
Emily
Emily 2022년 4월 20일
I want to show the output as the fieldnames with struct only and hide the chars.
So only show 'b' and 'c'.
s =
struct with fields:
a: [2×4 char]
b: [1×1 struct]
c: [1×1 struct]
d: [2×4 char]

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

채택된 답변

Matt J
Matt J 2022년 4월 20일
편집: Matt J 2022년 4월 20일
t='11'; s.q=1;
S=struct('a',t,'b',s,'c',s,'d',t)
S = struct with fields:
a: '11' b: [1×1 struct] c: [1×1 struct] d: '11'
aTable=struct2table(S);
disp( table2struct(aTable(:,vartype('struct'))) )
b: [1×1 struct] c: [1×1 struct]

추가 답변 (1개)

Matt J
Matt J 2022년 4월 20일
편집: Matt J 2022년 4월 20일
t='11'; s.q=1;
S=struct('a',t,'b',s,'c',s,'d',[s,s])
S = struct with fields:
a: '11' b: [1×1 struct] c: [1×1 struct] d: [1×2 struct]
p=reshape( namedargs2cell(S) , 2,[]);
keep=structfun(@(f)isstruct(f) & isscalar(f), S);
s=struct(p{:,keep});
disp(s)
b: [1×1 struct] c: [1×1 struct]

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by