MATLAB: Contourf with irregular spaced points

contourfirregular points

Contourf works if I define X and Y as monotonic increasing values. For eg.,
X=[1:3]; Y=[1:3]; Z=[10 20 30; 40 50 60; 70 80 90]; contourf(X,Y,Z);
Now, when I want to plot using contourf, but with irregular values of X, Y, for the same Z value, how will I go about this? For eg.,
X=[ 1.3 2.2 3.1 1.9 2.7 3.6 2.4 3.2 4.1];
Y=[-0.3 0.1 0.6 -1.2 -0.7 -0.2 -2.1 -1.6 -1.1];
Z=[10 20 30; 40 50 60; 70 80 90]; contourf(X,Y,Z);
The error msg: "The size of X must match the size of Z or the number of columns of Z."
Thanks,
Ganesh

Best Answer

You will need to use something like TriScatteredInterp over a regular grid and contour that. contour() and contourf() are not suitable for scattered points.