MATLAB: Beginner: Using SURF Function, Error: Z must be a matrix, not a scalar or vector.

MATLABsurf

Hi,
I've never used the surf function before and I am getting this error that I do not understand. I've read the other posts on this and still can't figure out what I need to do.
My situation:
xA is 5001 x 1 double
yA is 5001 x 1 double
zA is 5001 x 1 double
What can't I just do [x,y] = meshgrid(xA,yA) then surf(x,y,zA)? I don't see what other info the function would need to make a surface. Can someone tell me how to get this working?

Best Answer

N = 250;
xvec = linspace(min(xA), max(xA), N);
yvec = linspace(min(yA), max(yA), N);
[X, Y] = ndgrid(xvec, yvec);
F = scatteredInterpolant(xA, yA, zA);
Z = F(X, Y);
surf(X, Y, Z, 'edgecolor', 'none');