matlab - Is there a convenient way of turning an existing structure into a script? -
i have existing structure array loaded workspace load()
statement. fields contain char
, double
.
i want create structure, including contents of fields, in script instead, structure large, don't want write fields , values out hand.
dragging structure fields workspace editor copies field names over.
is there easy , convenient way extract fields , values, fields of structure array
example_struct
are turned statements of form
example_struct.field1 = <some_value>;
which doesn't involve writing script?
edit: want write script (an m-file) populates new structure array actual values. want statements script, including values, out of existing structure have loaded load()
, want know if can done without writing script (say, using fprintf statements) perform task.
if understand correctly, want dump struct matlab script file, rather .mat file. can few lines of matlab:
fid = fopen('outputfile.m'); names = fieldnames(example_struct); = 1 : length(names) fprintf(fid, 'example_struct.%s = %d;\n', names{i}, example_struct.(names{i}) ); end fclose(fid);
the fieldnames
function returns cell array of field names structure, can accessed in turn using example_struct.('name')
notation. note that i've made basic assumptions, fields being numbers. i'll leave expand needs!
Comments
Post a Comment