Let's say, I have many spheres drawn with surf/mesh function in MATLAB.
I want to display customize data values rather than x,y,z. All values will be different for different spheres and clicking on any point on a particular sphere should display the same data. Refer figure. How do I achieve it?
So far, I'm thinking of using Surface property 'tag' to assign unique string to each sphere. Is there any better way to do it?
[x,y,z] = sphere;
a=[3 1 3 1];
s1=surf(x*a(1,4)+a(1,1),y*a(1,4)+a(1,2),z*a(1,4)+a(1,3),...
'FaceColor', [1 0 0],'FaceLighting','flat','EdgeColor','none');
s1.Tag = '1';
How should I proceed with custom datacursor function for custom functionality ?

The datacursor function is an attribute of the
figure, so the trick is to assign the datatip update function to the figure.Placing the custom information for each sphere/graphic object in its
Tagproperty is a good idea for what you want to achieve.Let's define the update function first. Save the following file under
datatip_sphere.mand make sure it is visible in the Matlab path:Armed with that, now let's draw two spheres and make sure the cursor function displays what you want:
Obviously, the important lines are the last 4 lines, where you assign a
Tagfor each of your graphic object, and specially the last two lines where you assign your custom cursor update function to the figure.Cool, now your datatip will always display the name/tag assigned to the object, regardless of their position: