Question

Hi I wrote a function so that i can edit my datatip in a contourf plot. I can take the position but the problem is that i can't edit the level (result) as well.

I can take the position like this 'pos = get(event_obj,'Position');'

Is there any command in matlab that i can take the level (result)?

Was it helpful?

Solution

A good solution is the following:

After contour plot we write this:

dcm = datacursormode(gcf);
datacursormode on;
set(dcm, 'updatefcn',@perso_datacursor)

Then we create this function:

function output_txt = perso_datacursor( obj,event_obj) 
dataIndex = get(event_obj,'DataIndex'); 
pos = get(event_obj,'Position'); 
h=get(event_obj,'Target'); 
X=get(h,'XData'); 
Y=get(h,'YData'); 
Z=get(h,'ZData'); 
idx_x=find(X==pos(1)); 
idx_y=find(Y==pos(2)); 
Level=Z(idx_y,idx_x); 
output_txt = {[ 'X',num2str(pos(1),4)],... 
[ 'Y',num2str(pos(2),4)],... 
[ 'Z',num2str(Level)]}; 
end

And we have also the level (Result) of the contour

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top