matlab - Print all elements of a struct -


i approaching matlab, have function struct:

function [out] = struct1()  account(1).name = 'john'; account(1).number = 321; account(1).type = 'current';  %.......2 9   account(10).name = 'denis'; account(10).number = 123; account(10).type = 'something';  ii= 1:10 out=fprintf('%s\n','%d\n','%s\n',account{ii}.name, account{ii}.number,account{ii}.type); end end 

the above code gives me error: "cell contents reference non-cell array object."

how output elements of such struct output using "fprintf"?

name: 'john'

number: 321

type: 'current'

          ...... 2 9 

name: 'denis'

number: 123

type: 'something'

you indexing elements of struct array { , } used cell arrays. simple ( , ) work fine.

also, since have line breaks in formatspec, should combine 3 strings together.

example:

formatspec = 'name: %s\nnumber: %d\ntype: %s\n'; ii= 1:10     out=fprintf(formatspec,account(ii).name,account(ii).number,account(ii).type); end 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -