How can I access an array from a Buttondown function of an axes in a GUIDE GUI?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Geoff Hayes
2014-8-4
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 个评论
Geoff Hayes
2014-8-4
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?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!