From: Noel on
I have a question. I'm familiar with the following construct:

a.(sprintf('Name%d',ix))

in which the fieldname of a structure can be controlled via a sprintf. Now, is there a
similar construct to control the structure name as:

(sprintf('Structure%d',ix)).fieldA

That specific construct returns an error in Matlab. How would you go around it,
any ideas? Thanks.

Noel Andres
From: us on
"Noel " <noelandres17(a)gmail.com> wrote in message <hmp396$ei7$1(a)fred.mathworks.com>...
> I have a question. I'm familiar with the following construct:
>
> a.(sprintf('Name%d',ix))
>
> in which the fieldname of a structure can be controlled via a sprintf. Now, is there a
> similar construct to control the structure name as:
>
> (sprintf('Structure%d',ix)).fieldA
>
> That specific construct returns an error in Matlab. How would you go around it,
> any ideas? Thanks.
>
> Noel Andres

one of the poor solutions

clear so sn*; % <- save old stuff!
so.a=pi;
sn=sprintf('snew_1');
assignin('caller',sn,so);
snew_1
% snew_1 = a: 3.14156

us
From: us on
"us "
> sn=sprintf('snew_1');

it must be said that something like

sn=sprintf('snew_%-1d',1);

would have been a slightly more intelligent example...

us