Skip to content

Instantly share code, notes, and snippets.

@debidatta
Created February 10, 2016 23:04
Show Gist options
  • Save debidatta/b55869c94c4882a78708 to your computer and use it in GitHub Desktop.
Save debidatta/b55869c94c4882a78708 to your computer and use it in GitHub Desktop.
MATLAB script to select points from a 3D scatter plot by clicking on it
function [pts] = getpts3d(x, y, z, n)
%% getpts3d Select points from a 3D scatter plot by clicking on plot
% x - Vector of X coordinates
% y - Vector of Y coordinates
% z - Vector of Z coordinates
% n - Number of points needed to be selected
% pts - Returns a n x 3 matrix of selected points
h = figure;
scatter3(x,y,z);
pts = zeros(n,3);
datacursormode on
dcm_obj = datacursormode(h);
for i=1:n
display(sprintf('Click on figure for point %d',i))
waitforbuttonpress;
f = getCursorInfo(dcm_obj);
pts(i,:) = f.Position;
end
end
@shiny-eel
Copy link

This was useful! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment