help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

INTERP2 / GRIDDATA : problems using those functions


From: Pierre Baldensperger
Subject: INTERP2 / GRIDDATA : problems using those functions
Date: Sun, 20 Nov 2005 22:40:15 +0100
User-agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)

Hello,

I use Octave 2.1.71 on SuSE 10.0 from the RPM available at :
ftp.opensuse.org/pub/opensuse/distribution/SL-10.0-OSS/inst-source/suse/i586/
with octave-forge (2006-06-13) installed on top of it.

I am trying to implement a simple 2D polar-to-rectangular interpolation,
but I run into very weird problems. A function "funcz" is defined on a polar
grid and I want to interpolate it on the bounding rectangular grid. I have
tried two different approaches, both of which work flawlessly on Matlab, but
fail with Octave.

1) The first approach uses the "interp2" function. Sample code follows:
------------------------------------------------------
angles=0:45;
radius=5:0.2:15;
[meshang,meshrad]=meshgrid(angles,radius);
funcz=cos(0.2*(meshang+meshrad));
xmin=min(min(meshrad.*cos(meshang*pi/180)));
xmax=max(max(meshrad.*cos(meshang*pi/180)));
ymin=min(min(meshrad.*sin(meshang*pi/180)));
ymax=max(max(meshrad.*sin(meshang*pi/180)));
vecx=xmin:0.2:xmax;
vecy=ymin:0.2:ymax;
[meshvx,meshvy]=meshgrid(vecx,vecy);
vecang=atan2(meshvy,meshvx)*180/pi;
vecrad=sqrt(meshvx.^2+meshvy.^2);
vecz=interp2(meshang,meshrad,funcz,vecang,vecrad);
colormap('jet');
imagesc(vecz);
------------------------------------------------------

At first, I obtained unexpected "NaNs" in the result "vecz", which cause the
"imagesc" to fail. I edited the "interp2.m" file and found that this behaviour
might originate in the last two lines, which I commented out, just to see.
After that dirty hack, I am able to visualize the interpolated result "vecz"
with "imagesc", but it looks totally wrong. I enclose a picture of "imagesc"
outputs of the main variables from the above code sample (I hope that it is
allowed to send pictures to this mailing list), so you can see how my "vecz"
looks like in case you don't get the same one.

2) The second approach uses the "griddata" function. Sample code follows:
------------------------------------------------------
angles=0:45;
radius=5:0.2:15;
[meshang,meshrad]=meshgrid(angles,radius);
posx=meshrad.*cos(meshang*pi/180);
posy=meshrad.*sin(meshang*pi/180);
funcz=cos(0.2*(meshang+meshrad));
posx_1d=reshape(posx,1,size(posx,1)*size(posx,2));
posy_1d=reshape(posy,1,size(posy,1)*size(posy,2));
funcz_1d=reshape(funcz,1,size(funcz,1)*size(funcz,2));
xmin=min(posx_1d);
xmax=max(posx_1d);
ymin=min(posy_1d);
ymax=max(posy_1d);
vecx=xmin:0.2:xmax;
vecy=ymin:0.2:ymax;
[meshvx,meshvy]=meshgrid(vecx,vecy);
vecz=griddata(posx_1d,posy_1d,funcz_1d,meshvx,meshvy);
colormap('jet');
imagesc(vecz);
------------------------------------------------------

With this version, Octave crashes with a SEGV during the "griddata". Here's
the error message I get:

------------------------------------------------------
panic: Segmentation fault -- stopping myself...
attempting to save variables to `octave-core'...
save to `octave-core' complete
*** glibc detected *** free(): invalid next size (normal): 0x09319a98 ***
panic: attempted clean up apparently failed -- aborting...
Aborted
------------------------------------------------------

What am I doing wrong? Did I miss something about "interp2" or "griddata"?
I would also be interested to know if anybody gets different results with
one or both of the code samples, possibly with another version of Octave.

Thank you in advance,
-Pierre.

PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]