Hi, I have a structure (abcSTRUCTUREdef) in my work space containing a list of variables. I use the following function to get all the varibles from the structure as a workspace variables.
%%%%%%%%%%Original Code %%%%%%%%%%%
fields = fieldnames( abcSTRUCTUREdef, '-full'); % Find out how many there are - for our loop.
numberOfFields = length(fields);for f = 1 : numberOfFields;thisField = fields{f};commandLine = sprintf('%s = abcFIELDdef.%s', thisField, thisField);eval(commandLine);end% Release temporary variables.
clear('f', 'thisField', 'numberOfFields');clear('fields', 'commandLine');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
However I would like to automate the whole process by just using it as a script where it acquires the structure name from the work space such that, (for example)
varNames = who;structName = varNames{1,1};fields = fieldnames( structName, '-full'); % Find out how many there are - for our loop.commandLine = sprintf('%s =' structName '.%s', thisField, thisField);
However everytime I attempt this, I get an error saying that "Undefined function 'fieldnames' for input arguments of type 'char'."
This is the end of a long script that pulls data out of folders. I would really appreciate your help.
Many thanks.
Best Answer