comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Indexing into Structures???
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Indexing into Structures??? [message #32123 is a reply to message #32122] Thu, 19 September 2002 03:37 Go to previous messageGo to previous message
Randall Skelton is currently offline  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
>
>
>
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Indexing into Structures???
Next Topic: Re: How do I use FORMAT as I would SPRINTF?? Please Help!

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 10:07:12 PDT 2025

Total time taken to generate the page: 0.80273 seconds