Re: Indexing into Structures??? [message #32123 is a reply to message #32122] |
Thu, 19 September 2002 03:37   |
Randall Skelton
Messages: 169 Registered: October 2000
|
Senior Member |
|
|
Indeed there is a way, but it isn't easy to find in the IDL help. If I
remember correctly, it is under the heading of 'advanced' structure usage.
In any case, what you will want is the function 'n_tags()' and the syntax
's.(i)' where s is your structure name, and i is the index number. Note
that the round brackets are important.
IDL> s = { a:0L, b:0L, c:0L }
IDL> for i=0, n_tags(s)-1 do s.(i) = 1
IDL> help, s, /structure
** Structure <81b7cb4>, 3 tags, length=12, data length=12, refs=1:
A LONG 1
B LONG 1
C LONG 1
IDL> print, s.(1)
1
It is worth noting that if you ever want to use pointers with a structure,
an extra set of brackets is often required... i.e.
IDL > a = ptr_new(s)
IDL > print, (*a).(1)
1
Let's see you do that with MATLAB ;)
You can find more examples by searching google groups:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&a mp;oe=UTF-8&group=comp.lang.idl-pvwave
Cheers,
Randall
On Thu, 19 Sep 2002, Brian Huether wrote:
> I need to be able to access structure fields within a for loop, meaning that
> I can't reference the field by name. In MATLAB it was easy to access
> Structure fields by simply using index values. Can someone tell me if it is
> possible to do this in IDL? If it isn't, then that is really a major
> shortcoming.
>
> -brian
>
>
>
|
|
|