Re: Accesing structures data
- From: TWago <twago@xxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Jul 2005 12:25:35 -0400
Thanks a lot!
cal wrote:
>
>
> example:
>>>
>
c=struct(struct('a',struct('a1',1,'a2',2,'a3',3),'b',struct('garbure
> ',8)))
>
> if what you want is to have some a1, a2 and a3 variables containing
> 1,2,3 in your program, there is only one answer:
>
> 1. get all the fields of c.a, type:
>>> f=fields(c.a)
> 2. dynamically build variables and contents (ugly loop):
>>> for i=1:length(f); eval(sprintf('%s=c.a.%s',f{i},f{i}));
end;
> 3. do not forget to clear your variables after use:
>>> for i=1:length(f); eval(sprintf('clear %s',f{i})); end;
>
> Or, if you don't like 'eval' (like me, because of compilation
> problems), you can try instead of step 2:
>>> for i=1:length(f); fc{i}=c.a.(f{i}); end;
> then you will obtain two cellarrays, one with field names (f) and
> another with fields values (fc), which will allow you to rebuild
> the
> orginial struct after modifications. Besides it allows you to use
> Christopher's proposal...
>
> hoping that it will help
> charles
>
>
.
- References:
- Accesing structures data
- From: TWago
- Re: Accesing structures data
- From: cal
- Accesing structures data
- Prev by Date: Changing values of popup menus
- Next by Date: Re: how to use simulink for difference equation?
- Previous by thread: Re: Accesing structures data
- Next by thread: Re: Accesing structures data
- Index(es):
Relevant Pages
|