arrays - MATLAB - get fieldnames of each element -


given when call fieldnames(md), have list of element class md.

now each element in md many subclasses own sub-elements, example first item fieldnames(md) returns called mesh, , when call fieldnames(mesh), list of string contains items mesh , that's it.

the goal here write items md subclasses text file.

i tried following:

 mfields = fieldnames(md);  fid = fopen('textfile.txt','w');   i=1:numel(mfields)        j=1:numel(fieldnames(mfields{i}))             fprintf(fid,'%s\r\n',fieldnames(mfields{i}))        end  end 

but apparently fieldnames doesn't take char argument. i'm new matlab please suggest if there other function job

many thanks

try this:

 mfields = fieldnames(md);  fid = fopen('textfile.txt','w');   i=1:numel(mfields)        %// check if field struct itself, otherwise not have subfields.        if isstruct(md.(mfields{i}))            subfields=fieldnames(md.(mfields{i}));        else           %// put space still display root field name when there no subfields           subfields = {' '};        end         %// loop through subfields        j=1:numel(subfields)             fprintf(fid,'%s\r\n',subfields{j})   %// or  fprintf(fid,'%s\t%s\r\n',mfields{i}, subfields{j})        end  end 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -