how to select patch surface in gui
11 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am looking for a method to select the patch surface in a 3D plot. In figure GUI, I can only select the node and get nodal position information through updateFun. The datacursormode.target has the patch data stored in there. Is there a way to change the cursor selection method from node to surface in a 3D mesh? Thanks in advance!
0 个评论
回答(1 个)
Ramtej
2024-4-16
Hi,
MATLAB's data cursor mode primarily focuses on points (nodes) rather than entire surfaces. However, you can leverage "ButtonDownFcn"of the plotting function to extract and display information related to the surface (patch) under the clicked point, rather than just the nodal information.
Below code demonstrates how to identify when a patch object is selected when you left click anywhere on the surface and toggles the marker (of vertices) and linewidth property of patch to distinguish it visually.
You can extend the functionality within the "myCustomUpdateFcn" function to include more specific information about the patch.
x1 = [0 0 1 1];
y1 = [3 3 2 2];
z1 = [0 3 2 1];
c1 = [0 0.447 0.741];
x2 = [2 2 3 3];
y2 = [1 1 0 0];
z2 = [1 2 3 0];
c2 = [0.850 0.325 0.098];
fill3(x1,y1,z1,c1,x2,y2,z2,c2, "ButtonDownFcn",@myCustomFcn);
% Define the custom update function
function myCustomFcn(~,event_obj)
target = event_obj.Source;
% Check if the target is a patch
if isa(target, 'matlab.graphics.primitive.Patch')
if target.Marker == "none"
target.Marker = 'o';
target.LineWidth = 3;
else
target.Marker = "none";
target.LineWidth = 0.5
end
% Now target is your selected patch
% Add your own code to modify patch
end
end
If you are trying to modify patch properties, refer the below documentaton for changing patch appearance and behavior.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!