I have created a fitted surface from x, y, z data points. How do I insert data tips
for the min and max value in the chart?
defDM_fit = fit([def_X, def_Y],def_Z,'cubicinterp');
clf;
figure(2)
plot(defDM_fit,[def_X, def_Y],def_Z);
using the following test code is raising an error "Invalid argument. The object has been deleted or does not support data tips":
datatip(defDM_fit, def_X(1), def_Y(1), def_Z(1))
And I do not know how to manage that tips show up at min and max value in the chart by code.
CodePudding user response:
Plotting a fitted surface created with fit
outputs a 2x1 graphics array. The first element is the surface (Surface object), the second element is a Line object that holds the points on which your data was fitted. In order to add datatips, you will have to use one of these two objects, and more probably the Surface object, for example:
load franke
T = table(x,y,z);
f = fit([T.x, T.y],T.z,'linearinterp');
p = plot( f, [T.x, T.y], T.z );
datatip(p(1),T.x(1),T.y(1),T.z(1))
CodePudding user response:
The first argument of datatip
is a graphic object, not a surface/line fit object.
defDM_fit = fit([def_X, def_Y],def_Z,'cubicinterp');
figure(2)
p=plot(defDM_fit,[def_X, def_Y],def_Z);
datatip(p, def_X(1), def_Y(1), def_Z(1))
There are many other things that may be wrong with your approach, particularly because you are showing a surface plot (surf
) in your example, yet your code uses a line plot (plot
). I am not even sure what the arguments even are, the way you are putting them.
Consider reading the documentation of the functions you are using, as they come with examples on how to use them: https://uk.mathworks.com/help/curvefit/fit.html