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

Home » Public Forums » archive » Loop through arrays with different names
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: Loop through arrays with different names [message #55176 is a reply to message #55088] Thu, 02 August 2007 06:00 Go to previous messageGo to previous message
mattf is currently offline  mattf
Messages: 13
Registered: January 2007
Junior Member
On Aug 2, 8:57 am, mattf <mfe...@earthlink.net> wrote:
> On Aug 1, 8:04 pm, hazel <hazel.ken...@gmail.com> wrote:
>
>
>
>> Hello,
>
>> I have a really simple problem that always happens when I starting
>> trying to use strings..
>
>> I want to loop through a series of arrays, each with a slightly
>> different name (det1arr(n,3), det2arr(n,3), det3arr(n,3)..etc..) and
>> subject each to the same function:
>
>> a quick outline is:
>
>> for j=1,8 do begin
>
>> for i=0, n-1 do begin
>
>> vx=det1arr(i, 0) ; where the 1 is effectively the value of 'j'
>> vy=det1arr(i, 1)
>> vz=det1arr(i, 2)
>
>> result(i,j)=some_function(vx, vy, vz)
>
>> endfor
>
>> So can I do something like: vx=det+j+arr(i,0)? (Only that clearly
>> won't work)? There must be a way? Otherwise I can reload all my
>> different arrays into one array I realise and just loop through that.
>
>> I'm sure it's something painfully simple and for that I apologise, but
>> it is the end of the day (for me anyway),
>
>> Thanks,
>
>> Hazel
>
> A somewhat more flexible approach is to collect the similar variables
> into a struct:
>
> det_struct = {d1:det1arr, d2:det2arr, ...}
>
> and then do a for-loop over the struct's fields
>
> n_fields = n_tags(det_struct)
> for ix_struct = 0, n_fields-1 do begin
> current_field = det_struct.(ix)
> for ix_var = 0, n do begin
> -- do whatever here --
> endfor
> endfor

Needless to say, I got the critical line wrong-- it should be

current_field = det_struct.(ix_struct)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Routine for Converting DN to Radiance to Temperature
Next Topic: Another HDF File Question

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

Current Time: Wed Oct 08 19:32:48 PDT 2025

Total time taken to generate the page: 0.00434 seconds