Domanda

I'm seeing erratic behavior from the data cursor in MATLAB R2011b when applied to plots of triangulated 3d surfaces: Clicking on certain points selects completely different points instead. Example with a cylinder:

[r, phi, h] = meshgrid(1, 0:pi/10:2*pi, 0:0.05:1);
x = r.*cos(phi);
y = r.*sin(phi);
z = h;
xyz = [x(:) y(:) z(:)];
tri = delaunay(xyz);
trimesh(tri, xyz(:,1), xyz(:,2), xyz(:,3), ...
        'LineStyle', 'none', 'Marker', '.', 'MarkerSize', 30)
view(-37, 28)

Then enable data cursor mode and try to select the topmost dot of one of the columns in front. On my installation, MATLAB does not select the point under the cursor but a different one seemingly chosen at random.

Is this a bug or am I doing something wrong?

È stato utile?

Soluzione 2

I found a solution to this problem in a File Exchange contribution by Jochen Rau. You can define which data is selectable with the data cursor via the 'HitTest' property. So for the example I provided, where I wanted only the markers to be selectable, the solution is to plot the mesh without markers and with 'HitTest' set to 'off' and then use 'scatter3' to plot the markers.

[r, phi, h] = meshgrid(1, 0:pi/10:2*pi, 0:0.05:1);
x = r.*cos(phi);
y = r.*sin(phi);
z = h;
xyz = [x(:) y(:) z(:)];
tri = delaunay(xyz);
figure
hold on
trimesh(tri, xyz(:,1), xyz(:,2), xyz(:,3), ...
        'LineStyle', 'none', 'Marker', 'none', 'HitTest', 'off')
scatter3(xyz(:,1), xyz(:,2), xyz(:,3))
view(-37, 28)

If you're wondering what the point of plotting the triangulation is: it's to aid in visualizing point clouds by obscuring points that are in the back. The 'trimesh' call accomplishes this because it still draws the faces in white.

Altri suggerimenti

I think it's because you have so many lines in your mesh; if you remove the 'linestyle','none' and plot a small section of the mesh (using e.g. [r, phi, h] = meshgrid(1, 0:pi/10:2*pi, 0:0.5:1); as your first line you can see they are going through your cylinder. The data cursor mode will go to the closest vertex on a line that you click on, so if you are clicking on a line that is hidden beneath a face, it may jump to a vertex on that line rather than only the dots you have made visible. I am not sure if there is an easy way to change this behaviour.

A solution for me has been to set the "SnapToDataVertex" property of the data cursor object to "off".

dc = datacursormode;
set(dc,'SnapToDataVertex','off')

When set to the default, "on," clicking on a patch object causes the datacursor to move to the vertex nearest the line of sight, even if the face is occluded. When off, the datacursor moves to the point where line of sight intersects the nearest face, which is usually what I want.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top