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!