MATLAB: Surf plot: Data dimensions must agree.

surf dimensions mismatch

Can't for the life of me figure this out..
trying to plot the following:
surf(transect1.lon,transect1.lat,transect1.z,transect1.u)
They have the following dimensions:
size(transect1.lon) = 29 1
size(transect1.lat) = 29 1
size(transect1.z) = 29 30
size(transect1.u) = 29 30

Best Answer

Either ‘transect1.lon’ or ‘transect1.lat’ has to be (30x1), or you have to remove one column from ‘transect1.z’ and ‘transect1.u’ so the dimensions match. (An option is to interpolate the matrices to make them both (29x29), or interpolate one of the vectors to (30x1).)
The surface plots only take one matrix argument, so you have to use hold to plot both in the same axes.
After you make sure the vectors and matrix dimensions match, see if this does what you want:
figure
surf(transect1.lon,transect1.lat,transect1.z)
hold on
surf(transect1.lon,transect1.lat,transect1.u)
hold off
grid on
NOTE I can’t run your code to test this, so this is UNTESTED CODE.