How can I access an array from a Buttondown function of an axes in a GUIDE GUI?
Show older comments
I have created an axes object in my Guide GUI. This axes has many 3d points plotted in it. Now I have defined a Buttondown function for this axes in such a way to enable the user for selecting points from the already plotted 3d points. Inside the Buttondownfunction there is a coloumn(3by1) array ( named selectedPoint in the code below) which has the x,y and z coordinates data.So everytime when the user selects a point, the array shows the coordinates information. My question is how can I get this array out and keep appending it to a common array so that it has the coordinates information of all selected points?
function callbackClickA3DPoint(src, eventData, pointCloud)
point = get(gca, 'CurrentPoint'); % mouse click position
camPos = get(gca, 'CameraPosition'); % camera position
camTgt = get(gca, 'CameraTarget'); % where the camera is pointing to
camDir = camPos - camTgt; % camera direction
camUpVect = get(gca, 'CameraUpVector'); % camera 'up' vector
zAxis = camDir/norm(camDir);
upAxis = camUpVect/norm(camUpVect);
xAxis = cross(upAxis, zAxis);
yAxis = cross(zAxis, xAxis);
rot = [xAxis; yAxis; zAxis]; % view rotation
rotatedPointCloud = rot * pointCloud;
rotatedPointFront = rot * point' ;
pointCloudIndex = dsearchn(rotatedPointCloud(1:2,:)', ...
rotatedPointFront(1:2));
h = findobj(gca,'Tag','pt');
selectedPoint = pointCloud(:, pointCloudIndex);
if isempty(h) % if it's the first click (i.e. no previous point to delete)
h(1) = plot3(selectedPoint(1,:), selectedPoint(2,:), ...
selectedPoint(3,:), 'r.', 'MarkerSize', 20);
set(h,'Tag','pt'); % set its Tag property for later use
else % if it is not the first click
% highlight the newly selected point
h(end+1) = plot3(selectedPoint(1,:), selectedPoint(2,:), ...
selectedPoint(3,:), 'r.', 'MarkerSize', 20);
set(h,'Tag','pt'); % set its Tag property for later use
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!