passing a filename as argument in matlab -
in matlab
have function should take in file name. file has struct in it, later file should executed in function struct loaded work space.
for example:
my function hello(a)
, 'a' file name, file has struct.
on executing file in command window struct loaded in workspace. same way want struct loaded in workspace when call function.
i tried eval(a)
, not loading struct in file workspace.
from file name how obtain struct name, though know there struct in file, going vary dynamically.
so how should return structure in function?
i not sure whether want struct (or structs) inside file copied automatically workspace, or if want assign data yourself.
the following solution copies variables file a
"base"-workspace automatically using assignin()
function. solution assumes give file .mat file.
function hello(a) all_structs = load('-mat', a); var_names = fieldnames(all_structs); k = 1:length(var_names) assignin('base', var_names{k}, all_structs.(var_names{k})); end end
Comments
Post a Comment