Re: Accesing structures data



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
>
>
.



Relevant Pages

  • Re: Accesing structures data
    ... dynamically build variables and contents (ugly loop): ... orginial struct after modifications. ... Prev by Date: ...
    (comp.soft-sys.matlab)
  • predikanten
    ... Hulpvaardigen hebben het antwoord via de e-mailpost bezorgd. ... Charles ... Prev by Date: ...
    (soc.genealogy.benelux)
  • Re: B&H and Adorama Closed!
    ... but he was clearly not an observant Jew either. ... black people and also a few others who are not Hasidem but I have never ... Charles ... Prev by Date: ...
    (rec.photo.digital)
  • Re: Damaged NTFS table?
    ... >> fix or rebuild it? ... If so all help and guidelines are appreciated! ... Prev by Date: ...
    (microsoft.public.windowsxp.hardware)
  • RE: passing database data to a sub
    ... HTH, ... Charles K. Clarkson ... Prev by Date: ...
    (perl.beginners)