How to display structs only in a struct with fields?

2 次查看(过去 30 天)
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