MATLAB: Does code choke at line 22; mesh(xFIT,yFIT,YFIT). Att: x var in Col 1, y var in Col 2 and z var in col 3. Code &error below. We get the scatter; not the mesh. (Save xl file to C:\, upload: Home>Import Data>Import>Import Selection, run code)

https://www.mathworks.com/matlabcentral/answers/64368-plotting-z-values-associated-with-xy-coordinate-for-3d-plot?s_tid=answers_rc1-3_p3_topicMATLAB

T = table2array(MeshProblem);
x = T(:,1);
y = T(:,2);
z = T(:,3);
X = [ones(size(x)) x y x.*y];
b = regress(z,X)
scatter3(x,y,z,'filled')
hold on
xfit = min(x):100:max(x);
yfit = min(y):10:max(y);
[xFIT,yFIT] = meshgrid(xfit,yfit);
YFIT = b(1) + b(2)*xFIT + b(3)*xFIT + b(4)*xFIT.*yFIT;
mesh(xFIT,yFIT,YFIT)
xlabel('dX1/dt')
ylabel('dX2/dt')
zlabel('dP/dt')
view(50,10)
hold off
Error message generated:
Error using mesh (line 71)
Z must be a matrix, not a scalar or vector.
Error in EBITREGRESS (line 22)
mesh(xFIT,yFIT,YFIT)

Best Answer

>> min(T(:,1))
-1.17720177
>> max(T(:,1))
0.544794125
Your x values have a span of about 1.7, but
xfit = min(x):100:max(x);
expects them to have a span of at least 101.
Did you perhaps want
xfit = linspace(min(x), max(x),100);
yfit = linspace(min(y), max(y), 100);