matlab - access to struct fields based on struct name -


i have problem access each field of struct in matlab. tried convert cell however, give me error :( how can access each field 2 loops ? have wrote following code :

a=load(goalmfile); struct_name=fieldnames(a); struct_cell=struct2cell(a); cellsz = cellfun(@size,struct_cell,'uni',false); ans=cellsz{:}; row=ans(1); col=ans(2); counter1=1:row counter2=1:col a.struct_name{(counter1-1)*counter2+counter2} % error here end  end 

i appreciate, if me.

you can access structure dynamically s.(fname) fname char variable. note ( ) around fname.

an example clarify:

% example structure s.a = 10; s.b = 20;  % retrieve fieldnames fnames = fieldnames(s);  % loop numeric index ii = 1:numel(fnames)     s.(fnames{ii}) end  % ...or loop fieldname directly f = fnames'     s.(f{:}) end 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -