From: Lorenzo Guerrasio on
Having a structured array such as

sa=struct('field_a',repmat({2},100,1),'field_b',repmat({10},100,1));

%it is easily possible to assign all values of a particular field to an ordinary vector

a=[sa(:).field_a];

%How to achieve the opposite assignment? Unfortunatly
%[sa(:).field_a]=a;
% is an inalid syntax.

%Does anybody know how to assign each component of a vector to a field of a %structured array?
From: us on
"Lorenzo Guerrasio" <lorenzo.guerrasio(a)email.it> wrote in message <i0foo4$cea$1(a)fred.mathworks.com>...
> Having a structured array such as
>
> sa=struct('field_a',repmat({2},100,1),'field_b',repmat({10},100,1));
>
> %it is easily possible to assign all values of a particular field to an ordinary vector
>
> a=[sa(:).field_a];
>
> %How to achieve the opposite assignment? Unfortunatly
> %[sa(:).field_a]=a;
> % is an inalid syntax.
>
> %Does anybody know how to assign each component of a vector to a field of a %structured array?

one of the solutions

sa=struct('field_a',repmat({2},100,1),'field_b',repmat({10},100,1));
v=1:numel(sa);
v=num2cell(v);
[sa(1:end).field_a]=deal(v{:});
sa(4).field_a
% ans = 4

us
From: Lorenzo Guerrasio on
Thanks a lot.


"us " <us(a)neurol.unizh.ch> wrote in message <i0fpd9$q6m$1(a)fred.mathworks.com>...
> "Lorenzo Guerrasio" <lorenzo.guerrasio(a)email.it> wrote in message <i0foo4$cea$1(a)fred.mathworks.com>...
> > Having a structured array such as
> >
> > sa=struct('field_a',repmat({2},100,1),'field_b',repmat({10},100,1));
> >
> > %it is easily possible to assign all values of a particular field to an ordinary vector
> >
> > a=[sa(:).field_a];
> >
> > %How to achieve the opposite assignment? Unfortunatly
> > %[sa(:).field_a]=a;
> > % is an inalid syntax.
> >
> > %Does anybody know how to assign each component of a vector to a field of a %structured array?
>
> one of the solutions
>
> sa=struct('field_a',repmat({2},100,1),'field_b',repmat({10},100,1));
> v=1:numel(sa);
> v=num2cell(v);
> [sa(1:end).field_a]=deal(v{:});
> sa(4).field_a
> % ans = 4
>
> us
From: us on
"Lorenzo Guerrasio" <lorenzo.guerrasio(a)email.it> wrote in message <i0fp58$9vg$1(a)fred.mathworks.com>...
> Having a structured array such as
>
> sa=struct('field_a',repmat({2},100,1),'field_b',repmat({10},100,1));
>
> %it is easily possible to assign all values of a particular field to an ordinary vector
>
> a=[sa(:).field_a];
>
> %How to achieve the opposite assignment? Unfortunatly
> %[sa(:).field_a]=a;
> % is an inalid syntax.
>
> %Does anybody know how to assign each component of a vector to a field of a %structured array?

do NOT double-post...
one solution's here

http://www.mathworks.com/matlabcentral/newsreader/view_thread/285862

us