Clear Filters
Clear Filters

Error using datatip() on surface. Method is not defined.

9 views (last 30 days)
I am trying to add/move datatips on figures (3d surfaces) by giving the figure number and x and y positions and havaing the program figure out the correct z value and then generate the datatip. I've boiled down my issue to this scenario.
figure(4)
x = 0:0.1:4;
y = 4:0.2:8;
[X,Y] = meshgrid(x,y);
Z = sin(X+Y);
srf = surf(X,Y,Z);
xVal = 3.7;
yVal = 5;
[~,xIdx] = min(abs(xVal - srf.XData(1,:)));
[~,yIdx] = min(abs(yVal - srf.YData(:,1)));
dt = datatip(srf,xVal,yVal,srf.ZData(yIdx,xIdx)); %yes, it makes me put the x and y indices backwards...
This gives the error below:
"Warning: Error occurred while executing the listener callback for event MarkedClean defined for class matlab.graphics.datatip.DataTip:
Error using matlab.graphics.chart.primitive.Surface/getInterpolatedPointInDataUnits Method 'doGetInterpolatedPointInDataUnits' is not defined for class 'matlab.graphics.chart.primitive.Surface' or is removed from MATLAB's search path.
Error in matlab.graphics.datatip.DataTip
Error in matlab.graphics.datatip.DataTip>@(s,e)nDelayedMove()"
It also creates a dataip at the origin (x=0, y=4) with the corect z value.
I am encountering this on both versions '9.8.0.1721703 (R2020a) Update 7' and '9.10.0.1710957 (R2021a) Update 4', but not when I use the latest version through https://matlab.mathworks.com/ which has '9.12.0.1972586 (R2022a) Update 2'. There it just plots the wrong point the (x=3.2, y=4.2, z = 0.898708) until I rotate the view of the plot a bit from default and then run the last line (I'm still investigating what is the thing to do to get it to work but that seems beyond the scope of this. Solved?: Okay it seems to simulate a click on the correct spot which is behind a hump so it creates the datatip on the near face).
Do I just not have a package installed?

Answers (1)

Piyush Dubey
Piyush Dubey on 3 Jul 2023
Hi Sanders,
The code seems to be fine. The error messages suggest a possible corruption of file or path that was imported during execution of the script.
Verification should be done if the undefined function or variable is visible (if it is in the path or in the current workspace) and that has been defined. The 'which' function can help verify the visibility to the function where the error occurs:https://www.mathworks.com/help/matlab/ref/which.html
These set of commands can be used to reset the path.
>> restoredefaultpath
>> rehash toolboxcache
>> savepath
Hope this helps.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!