I have a figure, with a 3D patch on it.
I was wondering if somebody would have an idea about how to get, in a vector for example, the 3D coordinates of a data cursor that I put on my patch.
I have first made something with ginput in 2D, but ginput does not work with 3D data :(
Then, I decided to work directly with the matlab data cursor.
If I do it "manually":
- put a cursor on my patch
- right click --> "export cursor data to workspace.."
- my 3D coodinate
it works.
I would like to do exactly the same, but automatically:
- put/move a cursor on my patch
- store the 3D coordinate in a vector.
I tried that, but does not work:
fig=figure()
[x y z v] = flow;
p = patch(isosurface(x,y,z,v,-3));
isonormals(x,y,z,v,p)
daspect([1 1 1])
isocolors(x,y,z,flipdim(v,2),p)
shading interp
axis(volumebounds(x,y,z,v))
view(3)
camlight
lighting phong
grid on
% Data cursor
datacursormode on
dcmObj = datacursormode(fig);
set(dcmObj,'SnapToDataVertex','off','Enable','on')
c = getCursorInfo(dcmObj)
%position = c.Position;
position = c.Position should return me the 3D coordinate, but when this code is runned, there is still no cursor on the figure, and so, I get an error.
How to run the "Data cursor" part just when I click/move a cursor on my patch?
Any idea is welcome! Thanks
%% Data cursor
datacursormode on
dcmObj = datacursormode(fig);
set(dcmObj,'SnapToDataVertex','off','Enable','on')
loop = 1
while loop == 1
waitforbuttonpress;
point1 = getCursorInfo(dcmObj);
x = point1.Position(1)
y = point1.Position(2)
z = point1.Position(3)
% Write exit option
end