|
"Steffen " <rileksn@gmail.com> wrote in message
<fk3lt3$cj3$1@fred.mathworks.com>...
> hi there,
>
> I´m trying to name a struct array with variable names.
> For instance:
>
> file=['Image1', 'Image2'];
> Data.single_images.file=ones(512,512);
>
> 'file' should now be variable containing the different
> strings of the filename. However, I don´t know the correct
> syntax to do that since Matlab does not recognize 'file' as
> a variable. It always saves it as 'data.single_images.file'
> instead of 'data.single_images.Image1'.
> Is it possible to save it that way? Any hint is much
> appreciated!!
>
> Thanks and best regards,
> Steffen
Use "dynamic fieldname" (the fieldname is evaluated as
expression).
file={'Image1', 'Image2'}; % <- use cell to scope with
% various fieldname lengths
Data.single_images.(file{1}) = ones(512,512);
...
Bruno
|