% This works fine in Matlab (7.12.0(R2011a)) but fails in octave

more off

Version='spline' ; %'spline' 'linear' or 'workaround'

%% variables in polar coords
phi=0:10:90 % degree
r=0:1:10 

[PHI,R]=meshgrid(phi,r)

%% define an example function
Z=0.1*R.^2;

%% variables in cartisian coords
x=0:10
y=x
[X Y]=meshgrid(x,y);

%% coord-transformation from cartisian to polar coords
iR=sqrt(X.^2+Y.^2);
iPHI=atan(Y./X)/pi*180;
iPHI(1,1)=0;


switch (Version)
  case 'linear'
    iZ=interp2(PHI,R,Z,iPHI,iR,'linear'); % this works
  case 'spline'
    ok=find(iR<=10)
    iZ=NaN(size(iR));
    iZ(ok)=interp2(PHI,R,Z,iPHI(ok),iR(ok),'spline'); % this fails
  case 'workaround' % very slow
    for i=1:rows(iPHI)
      for j=1:columns(iPHI)
	iZ(i,j)=interp2(PHI,R,Z,iPHI(i,j),iR(i,j),'spline');
      end
    end
end

mesh(X,Y,iZ)

