Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get automatically 3D position of a data cursor on a patch

177 views
Skip to first unread message

Hortense Kirisli

unread,
Aug 25, 2009, 10:45:04 AM8/25/09
to
Hi all,

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

Hortense Kirisli

unread,
Aug 25, 2009, 11:02:02 AM8/25/09
to
Ok, I get it.
If other people are interested, here is my solution:

%% 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

Matthias

unread,
Sep 25, 2009, 5:12:02 AM9/25/09
to
Hi, do you know how to do it for a simple 2D plot?
Many thanks
Mat

Orestis

unread,
Jul 16, 2013, 5:41:09 AM7/16/13
to
I guess the ginput function should do the work.


"Matthias " <chil...@gmx.ch> wrote in message <h9i1h2$4r2$1...@fred.mathworks.com>...

mjrizy70

unread,
Jul 15, 2015, 7:56:54 AM7/15/15
to
when i use the code below, i got "Attempt to reference field of non-structure array." error.
Can u please help me?

% reading a head 3-D model

[V,F] = read_vertices_and_faces_from_obj_file('head.obj');
fig=figure(1);
trisurf(F,V(:,1),V(:,2),V(:,3));
x=zeros(1,10);
y=zeros(1,10);
z=zeros(1,10);

datacursormode on
dcmObj = datacursormode(fig);
set(dcmObj,'SnapToDataVertex','on','Enable','on');

for i=1:10
w = waitforbuttonpress;
point = getCursorInfo(dcmObj);
POINT=point.Position;
x= POINT(1);
y= POINT(2);
z = POINT(3);
end


someone

unread,
Jul 15, 2015, 3:21:11 PM7/15/15
to
mjrizy70 <abasza...@gmail.com> wrote in message <dbSdnT0pZqoc1zvI...@giganews.com>...
For which line do you get the error message?
I'm guessing it's:

point = getCursorInfo(dcmObj);

If so, do you have the MATLAB DSP System Toolbox installed?
It is required for the getCursorInfo command.

Steven Lord

unread,
Jul 16, 2015, 9:43:39 AM7/16/15
to


"someone" <som...@somewhere.net> wrote in message
news:mo6br2$c7p$1...@newscl01ah.mathworks.com...
There is an object in DSP System Toolbox, dsp.LogicAnalyzer, that has a
getCursorInfo method.

http://www.mathworks.com/help/dsp/ref/dsp.logicanalyzer.getcursorinfo.html

The datacursormode object returned by the DATACURSOR function also has a
getCursorInfo method. See the "Querying Data Cursor Mode" section on the
documentation page.

http://www.mathworks.com/help/matlab/ref/datacursormode.html

The error message is likely coming from the next line, where the OP tries to
get the Position from the data cursor info struct. If there are no data
cursors then the datacursormode object's getCursorInfo method will return
[]. For consistency (always returning a 1-by-numberOfDataCursors struct
array) it probably should return a 1-by-0 struct array instead; I will ask
the development team about that.

To block until the user actually creates a data cursor (rather than blocking
until the user clicks in the figure, which may not be a click on a graphics
object in the axes) try this:

plot(1:10);
D = datacursormode;
while isempty(getCursorInfo(D))
waitforbuttonpress;
end
infoStruct = getCursorInfo(D)

Replace the ISEMPTY call with "numel(getCursorInfo(D)) < N" to block until
the user creates N data cursors.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

0 new messages