Home > chronux_1_15 > spikesort > utility > datatypes > structpack.m

structpack

PURPOSE ^

STRUCTPACK Copies workspace variables into the fields of a structure.

SYNOPSIS ^

function s = structpack(names)

DESCRIPTION ^

STRUCTPACK        Copies workspace variables into the fields of a structure.
   S = STRUCTPACK(NAMES) takes a cell array NAMES of strings containing
   the names of variables in the current workspace.  It returns a
   structure with field names and contents copied from those variables.
   For example,
                    X = 1; Y = 2; S = STRUCTPACK({'X','Y'});
   will return a structure S such that (S.X = 1) and (S.Y = 2).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function s = structpack(names)
0002 %STRUCTPACK        Copies workspace variables into the fields of a structure.
0003 %   S = STRUCTPACK(NAMES) takes a cell array NAMES of strings containing
0004 %   the names of variables in the current workspace.  It returns a
0005 %   structure with field names and contents copied from those variables.
0006 %   For example,
0007 %                    X = 1; Y = 2; S = STRUCTPACK({'X','Y'});
0008 %   will return a structure S such that (S.X = 1) and (S.Y = 2).
0009 
0010 for n = 1:length(names)
0011     nameexist = evalin('caller', ['exist(''' names{n} ''');']);
0012     if (nameexist ~= 1), 
0013         error(['The variable ' names{n} ' was not found in the workspace.']); 
0014     end;
0015     
0016     s.(names{n}) = evalin('caller', names{n});
0017 end

Generated on Tue 15-Aug-2006 22:51:57 by m2html © 2003