MATLAB: Does the CONTOURF function not plot correctly in polar coordinates in MATLAB 7.2 (R2006a)

contourfincorrectMATLAB

I am creating a filled contour plot for my data as follows:
X=(-50:50)'./10; Y=(-50:50)./10;
a=exp(-(X.^2*ones(size(Y))+ones(size(X))*Y.^2));
% polar coordinates
r=((1:101)./100)';
th=2*pi*(0:100)/100;
u=r*cos(th); v=r*sin(th);
contourf(u,v,a,30);
The generated CONTOURF contour plot does not fill the axes space and creates unexpected and incorrect results.

Best Answer

There is a bug in the CONTOURF function in MATLAB 7.2 (R2006a) which causes the function to handle non-linear data improperly.
To work around this issue, invoke the version 6 behavior of MATLAB by using the following form of the function call
contourf('v6', X, Y, a, 15);
Note that using 'v6' will create a set of patches instead of a CONTOURGROUP object.