Loading variables from file into struct or cell-array

Ben Abbott bpabbott at mac.com
Thu Oct 23 06:30:49 CDT 2008


On Oct 23, 2008, at 7:23 AM, Jan Albersmeyer wrote:

> Hi !
>
> Is there a way to load variables from a file directly into a struct,
> such that e.g. the vars "v1","v2", from the file ... are
> stored in memory as "input.v1", "input.v2", ....
>
> Of course without knowing them in advance ;-)
>
> Or is there a possibility to get an array of the strings of the  
> variable
> names contained in a file ( i.e. something like a table of contents),
> such one can iterate through them ?
>
> Thanks,
>
> Jan

To load the variables of a file into a structure,

	input = load ("yourfile");

For an array of strings

	variable_names = fieldnames (load ("yourfile"));

To see the "table of contents"

	disp (char (variable_names)

Ben



More information about the Help-octave mailing list