4D interpolation

View: New views
8 Messages — Rating Filter:   Alert me  

4D interpolation

by thanatos187 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
I want to interpolate my values with the spline method. I did it with the command:
vi = interpn(u,v,w,x,z,uu,vv,ww,xx,'spline');
where u,v,w,x are vectors of the same length defining the point with the value z. uu,vv,ww,xx are creaed by the ndgrid command. i got the error message: "wrong number or incorrectly formatted input argument".

thanks for any help
Thanatos

Re: 4D interpolation

by Ben Abbott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On May 20, 2008, at 3:52 AM, thanatos187 wrote:

>
> Hi
> I want to interpolate my values with the spline method. I did it  
> with the
> command:
> vi = interpn(u,v,w,x,z,uu,vv,ww,xx,'spline');
> where u,v,w,x are vectors of the same length defining the point with  
> the
> value z. uu,vv,ww,xx are creaed by the ndgrid command. i got the error
> message: "wrong number or incorrectly formatted input argument".
>
> thanks for any help
> Thanatos

Can you post a simple example? Does the problem occur for "nearest",  
"linear", or "cubic" interpolation?

Ben
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: 4D interpolation

by thanatos187 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ben Abbott wrote:
On May 20, 2008, at 3:52 AM, thanatos187 wrote:

>
> Hi
> I want to interpolate my values with the spline method. I did it  
> with the
> command:
> vi = interpn(u,v,w,x,z,uu,vv,ww,xx,'spline');
> where u,v,w,x are vectors of the same length defining the point with  
> the
> value z. uu,vv,ww,xx are creaed by the ndgrid command. i got the error
> message: "wrong number or incorrectly formatted input argument".
>
> thanks for any help
> Thanatos

Can you post a simple example? Does the problem occur for "nearest",  
"linear", or "cubic" interpolation?

Ben

It occurs for all methods. I want to use a spline interpolation. I have 1500 data points, so the length of the colum vectors are 1500. uu,vv,ww,xx, are matrixes of the size (10  10  10  10)

thanatos
_______________________________________________
Help-octave mailing list
Help-octave@octave.org
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: 4D interpolation

by Ben Abbott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On May 26, 2008, at 3:31 AM, thanatos187 wrote:

>
> Ben Abbott wrote:
>>
>> On May 20, 2008, at 3:52 AM, thanatos187 wrote:
>>
>>>
>>> Hi
>>> I want to interpolate my values with the spline method. I did it
>>> with the
>>> command:
>>> vi = interpn(u,v,w,x,z,uu,vv,ww,xx,'spline');
>>> where u,v,w,x are vectors of the same length defining the point with
>>> the
>>> value z. uu,vv,ww,xx are creaed by the ndgrid command. i got the  
>>> error
>>> message: "wrong number or incorrectly formatted input argument".
>>>
>>> thanks for any help
>>> Thanatos
>>
>> Can you post a simple example? Does the problem occur for "nearest",
>> "linear", or "cubic" interpolation?
>>
>> Ben
>>
>> It occurs for all methods. I want to use a spline interpolation. I  
>> have
>> 1500 data points, so the length of the colum vectors are 1500.
>> uu,vv,ww,xx, are matrixes of the size (10  10  10  10)
>>
>> thanatos

I tried a 3D and 4D example.

clear all

v1 = 0:0.2:2;
v2 = v1;
v3 = v1;
[x1,x2,x3] = ndgrid(v1,v2,v3);
y = (x1.*x2 + x1.*x2.^2).*x3;
z = interpn(x1,x2,x3,y,v1,v2,v3,'linear')

v4 = v1;
[x1,x2,x3,x4] = ndgrid(v1,v2,v3,v4);
y = (x1.*x2 + x1.*x2.^2).*x3./(1+x4);
z = interpn(x1,x2,x3,x4,y,v1,v2,v3,v4,'linear')

Both of these work for me. Please verify they work for you as well.

Ben

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Parent Message unknown Re: AW: 4D interpolation

by Ben Abbott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday, May 27, 2008, at 07:35AM, "Hofstaetter, Michael: Mr.: (external)" <michael.hofstaetter.external@...> wrote:

>-----Ursprüngliche Nachricht-----
>Von: Ben Abbott [mailto:bpabbott@...]
>Gesendet: Dienstag, 27. Mai 2008 13:12
>An: Hofstaetter, Michael: Mr.: (external)
>Cc: help-octave@...
>Betreff: Re: 4D interpolation
>
>
>On May 26, 2008, at 3:31 AM, thanatos187 wrote:
>
>>
>> Ben Abbott wrote:
>>>
>>> On May 20, 2008, at 3:52 AM, thanatos187 wrote:
>>>
>>>>
>>>> Hi
>>>> I want to interpolate my values with the spline method. I did it
>>>> with the
>>>> command:
>>>> vi = interpn(u,v,w,x,z,uu,vv,ww,xx,'spline');
>>>> where u,v,w,x are vectors of the same length defining the point with
>>>> the value z. uu,vv,ww,xx are creaed by the ndgrid command. i got the
>>>> error
>>>> message: "wrong number or incorrectly formatted input argument".
>>>>
>>>> thanks for any help
>>>> Thanatos
>>>
>>> Can you post a simple example? Does the problem occur for "nearest",
>>> "linear", or "cubic" interpolation?
>>>
>>> Ben
>>>
>>> It occurs for all methods. I want to use a spline interpolation. I
>>> have 1500 data points, so the length of the colum vectors are 1500.
>>> uu,vv,ww,xx, are matrixes of the size (10  10  10  10)
>>>
>>> thanatos
>
>I tried a 3D and 4D example.
>
>clear all
>
>v1 = 0:0.2:2;
>v2 = v1;
>v3 = v1;
>[x1,x2,x3] = ndgrid(v1,v2,v3);
>y = (x1.*x2 + x1.*x2.^2).*x3;
>z = interpn(x1,x2,x3,y,v1,v2,v3,'linear')
>
>v4 = v1;
>[x1,x2,x3,x4] = ndgrid(v1,v2,v3,v4);
>y = (x1.*x2 + x1.*x2.^2).*x3./(1+x4);
>z = interpn(x1,x2,x3,x4,y,v1,v2,v3,v4,'linear')
>
>Both of these work for me. Please verify they work for you as well.
>
>Ben
>
>
>Hi Ben
>
>Your examples also work for me, but i have the problem that my data coordinates are not equidistant in any direction. The coordinates are randomly generated. Additionally are the points not sorted, but this is not a problem. Probably i have to write a new function.
>
>Thanatos
>

Hi Thanatos,

Having non-equidistant points should not be a problem.

You can verify this by calculating v1 as

   v1 =unique(2*rand([1,10]));

and using the same examples as before.

The "unique" function is used in the unlikely event that duplicates exist, and to make sure the values are sorted.

You'll need to make sure your values are sorted, but this should not produce the error you see.

Regarding your error, can you check the size of your variables corresponding to x1, x2, x3, x4 and y?

octave:22> whos x1 x2 x2 x4 y
Variables in the current scope:

  Attr Name        Size                     Bytes  Class
  ==== ====        ====                     =====  =====
       x1         10x10x10x10               80000  double
       x2         10x10x10x10               80000  double
       x2         10x10x10x10               80000  double
       x4         10x10x10x10               80000  double
       y          10x10x10x10               80000  double

Total is 50000 elements using 400000 bytes

You can place this command in your own script and verify that the inputs are all correct. When I first tried my example I did not calculate y correctly and encountered the same error as you.

Ben



_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: 4D interpolation

by Eric S Fraga :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've been following the brief thread on interpolation with interest.
Very helpful.

However, I have a problem in which I need to interpolate (2d only)
onto a surface that is not square.  Given interp2:

     ZI = interp2 (X, Y, Z, XI, YI)

I wish to interpolate (or maybe, if need be, approximate) Z to get ZI
where XI and YI are not the same size.  And neither are the original X
and Y for that matter.  interp2 does not allow this.  Can anybody
please suggest an alternative?

Thanks,
eric
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: 4D interpolation

by Ben Abbott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jul 3, 2008, at 11:31 AM, Eric S Fraga <e.fraga@...> wrote:

> I've been following the brief thread on interpolation with interest.
> Very helpful.
>
> However, I have a problem in which I need to interpolate (2d only)
> onto a surface that is not square.  Given interp2:
>
>     ZI = interp2 (X, Y, Z, XI, YI)
>
> I wish to interpolate (or maybe, if need be, approximate) Z to get ZI
> where XI and YI are not the same size.  And neither are the original X
> and Y for that matter.  interp2 does not allow this.  Can anybody
> please suggest an alternative?
>

By not the same size I assume you are implying X & Y are vectors, and  
Z is a 2D array?

If so check out meshgrid or ndgrid.

Ben
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: 4D interpolation

by Eric S Fraga :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ben Abbott <bpabbott@...> writes:

> On Jul 3, 2008, at 11:31 AM, Eric S Fraga <e.fraga@...> wrote:
>
>> I've been following the brief thread on interpolation with interest.
>> Very helpful.
>>
>> However, I have a problem in which I need to interpolate (2d only)
>> onto a surface that is not square.  Given interp2:
>>
>>     ZI = interp2 (X, Y, Z, XI, YI)
>>
>> I wish to interpolate (or maybe, if need be, approximate) Z to get ZI
>> where XI and YI are not the same size.  And neither are the original X
>> and Y for that matter.  interp2 does not allow this.  Can anybody
>> please suggest an alternative?
>>
>
> By not the same size I assume you are implying X & Y are vectors, and
> Z is a 2D array?
>
> If so check out meshgrid or ndgrid.
>
> Ben

By not the same size, I meant that size(XI) != size(YI).  Pointing me
to meshgrid was very helpful as it's made me realise that XI and YI
need to be matrices.  I had thought they could be vectors as X and Y
are.  Using meshgrid to create XI and YI (from my original vectors)
gives me what I need and interp2 does the job.

Many thanks for the pointer and for the very speedy response!

eric
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave
LightInTheBox - Buy quality products at wholesale price