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

Home » Public Forums » archive » interpolate 3D matrix
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
interpolate 3D matrix [message #90410] Mon, 02 March 2015 06:04 Go to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Hi

I have two 3D arrays Ax and Ay with the following dimensions[100,4,4]=[time,x,y].

I wanted to interpolate my matrices Ax and Ay and make them to have dimensions of [100,8,8]. A part of my code is shown below:

size = 8
Ax_2D_INT = fltarr(100,size,size)
Ay_2D_INT = fltarr(100,size,size)

for i=0, 99 do begin
Ax_2D = REFORM(Ax[i,*,*]) ;change 3D to 2D
Ay_2D = REFORM(Ay[i,*,*])

dimensions_I_need = size(Dindgen(size,size),/Dimensions)
dimensions_I_have = size(Ax_2D,/Dimensions)

X = cgScaleVector(Dindgen(dimensions_I_need[0]), 0, dimensions_I_have[0]-1)

Y = cgScaleVector(Dindgen(dimensions_I_need[1]), 0, dimensions_I_have[1]-1)

Ax_2D_INT = INTERPOLATE(Ax_2D,X, Y, /GRID)
Ay_2D_INT = INTERPOLATE(Ay_2D,X, Y, /GRID)
endfor

I got the following error but I couldn't figure out why.
Attempt to subscript DIMENSIONS_I_HAVE with <INT ( 1)> is out of range.
Re: interpolate 3D matrix [message #90411 is a reply to message #90410] Mon, 02 March 2015 06:38 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Monday, March 2, 2015 at 3:04:41 PM UTC+1, g.na...@gmail.com wrote:
> Hi
>
> I have two 3D arrays Ax and Ay with the following dimensions[100,4,4]=[time,x,y].
>
> I wanted to interpolate my matrices Ax and Ay and make them to have dimensions of [100,8,8]. A part of my code is shown below:
>
> size = 8
> Ax_2D_INT = fltarr(100,size,size)
> Ay_2D_INT = fltarr(100,size,size)
>
> for i=0, 99 do begin
> Ax_2D = REFORM(Ax[i,*,*]) ;change 3D to 2D
> Ay_2D = REFORM(Ay[i,*,*])
>
> dimensions_I_need = size(Dindgen(size,size),/Dimensions)
> dimensions_I_have = size(Ax_2D,/Dimensions)
>
> X = cgScaleVector(Dindgen(dimensions_I_need[0]), 0, dimensions_I_have[0]-1)
>
> Y = cgScaleVector(Dindgen(dimensions_I_need[1]), 0, dimensions_I_have[1]-1)
>
> Ax_2D_INT = INTERPOLATE(Ax_2D,X, Y, /GRID)
> Ay_2D_INT = INTERPOLATE(Ay_2D,X, Y, /GRID)
> endfor
>
> I got the following error but I couldn't figure out why.
> Attempt to subscript DIMENSIONS_I_HAVE with <INT ( 1)> is out of range.

I've tried you code and got no error. In your test, you don't provide Ax and Ay. I've build them up myself as
Ax = randomu(s,100,size,size)
Ay = randomu(s,100,size,size)
and the code runs without errors.
My guess, is that Ax and/or Ay contain bad data (!null) or something similar.
Check your two input arrays.

Next thing I would highly recommend, is to avoid using variable names for which you also have functions. Don't use size = 8. This is just a source of trouble.

By the way, the error you described, happens when for example:
IDL> DIMENSIONS_I_HAVE = size(findgen(5), /dimensions)
IDL> print, DIMENSIONS_I_HAVE[1]
% Attempt to subscript DIMENSIONS_I_HAVE with <INT ( 1)> is out of range.

I made on purpose DIMENSIONS_I_HAVE have only one dimension. Then you cannot subscript the second dimension. So some when, your array Ax_2D has only one dimension. Try maybe printing "i" in the loop just before
Y = cgScaleVector(Dindgen(dimensions_I_need[1]), 0, dimensions_I_have[1]-1)
Then check the value of i that generated the error and have a look at that Ay[i,*,*].

Good luck,
Helder
Re: interpolate 3D matrix [message #90419 is a reply to message #90411] Mon, 02 March 2015 07:51 Go to previous message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
You were right for some reason the AX_2D has only one dimension. This happens after the first iteration.

AX_2D FLOAT = Array[4, 4]
AX_2D FLOAT = Array[8]

I replace the size word with something else to avoid troubles.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Is it possible to save the figure file in .PNG format directly in IDL?
Next Topic: function graphics event handling

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

Current Time: Wed Oct 08 15:07:36 PDT 2025

Total time taken to generate the page: 0.00647 seconds