> > Regarding your last question, is this related to this thread [1] or a
> > more general approach?
> >
> > Kai
> >
> > [1]
> > http://www.nabble.com/contour-plots-only-work-for-meshgrid-%28uniform%29-
> >spaces-and-not-other-spaces.-tf4541422.html
>
> The approach that I had in mind for general quadrilateral data is indeed
> the same as described in the thread you sent me. The only difference is
> that I would compute the contours in index space (i,j) and then map the
> contours in (x,y) space. Basically something like:
>
> [ii, jj] = meshgrid(1 : columns(Z),1 : rows(Z));
> # call to contourc for "meshgridded" data
> c_ij = contourc(ii, jj, Z, lvl);
>
> c = zeros(size(c_ij));
> loop over segments
> k = start_index : end_index
> c(1,k) = interp2(ii,jj,X,c_ij(1,k),c_ij(2,k));
> c(2,k) = interp2(ii,jj,Y,c_ij(1,k),c_ij(2,k));
>
> This is very similar to the approach of Peter. The only case where the two
> approaches differ is when the coordinate system is singular (if I
> understand the patch of Peter correctly). For example:
>
> [r,theta] = ndgrid(0:10, 0:2*pi);
> x = r .* cos(theta);
> y = r .* sin(theta);
>
> in which case all y(:,1) will be zero.
> But I haven't test the patch of Peter and I might be wrong.
>
> Thanks
> Alex
I tried running the above code with my mapping and it failed with divide by
zero. I haven't tried Alex's code, but I admit I did not consider a singular
case when I provided my mapping.
Pete
Attached is a new proposed patch of contourc for handling arbitrary quadrilateral grids.
I tested it in the following cases below:
Cheers,
Alex
% contourc is the old version (2.9.14)
% contourc_test is proposed version
x = -15:0.2:10;
y = -12:0.5:15;
[X,Y] = meshgrid(x,y);
Z = cos(X) .* cos(Y) .* exp(- (X.^2 + Y.^2)/20);
c = contourc(x,y,Z);
c_test = contourc_test(x,y,Z);
max(max(abs(c - c_test)))
c = contourc(X,Y,Z);
c_test = contourc_test(X,Y,Z);
max(max(abs(c - c_test)))
% Both return zero.
% The following two tests are expected to fail with contourc
% but work with contourc_test
c = contourc(X',Y',Z');
c_test = contourc_test(X',Y',Z');
max(max(abs(c - c_test)))
[r,theta] = ndgrid(0:10, linspace(0,pi,20));
X = r .* cos(theta);
Y = r .* sin(theta);
c = contourc(X,Y,X);
c_test = contourc_test(X,Y,X);
max(max(abs(c - c_test)))