How can I access an array from a Buttondown function of an axes in a GUIDE GUI?

1 view (last 30 days)
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

Geoff Hayes
Geoff Hayes on 4 Aug 2014
In your above callback, what is src? Or rather, what is the code that is used to assign the callbackClickA3DPoint callback to the ButtonDown function. If src is the figure, then you should be able to use guidata to store and retrieve the selected point "history" data.
In the above code, you could add something like
% get the handles structure
handles = guidata(src);
% does the selected point history field exist?
if ~isfield(handles,'selPtHistory')
% doesn't exist so create the field
handles.selPtHistory = [];
end
% append the new selected point
handles.selPtHistory = [handles.selPtHistory selectedPoint];
% save the data
guidata(src,handles);
This should allow the selected points to be saved over time. Id src is not the figure, but is a handle to some other object, then this object's parent figure is used.
Note that data saved to handles would be available in other callbacks or functions of the GUI.
Try the above and see what happens!
  2 Comments
matlablearner
matlablearner on 4 Aug 2014
Thanks a lot for your answer. It appends the points information. But I am not able to access the data outside this function. It says "Reference to non-existent field 'selPtHistory". I was trying to access this array in another function used in my GUI as coorddata = guidata(handles.selPtHistory). Kindly help. Thanks in advance.
Geoff Hayes
Geoff Hayes on 4 Aug 2014
Have you determined what src is? What is the code that is assigning the callback to the ButtonDown function?
Could you attach your m and fig files for your GUI?

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!