MATLAB GUI 中的圆
Circle in MATLAB GUI
我正在制作 MATLAB 和 Ascention Trakstar(运动)传感器之间的实时接口。在此任务中,我在 MATLAB GUI 图 window(全屏尺寸)上将实时传感器位置显示为正方形。
我想在各种形状上显示传感器位置(现在关注圆形)。如何在MATLAB GUI图形中画圆window?以及如何通过MATLAB实时循环句柄?
提前致谢。
您需要在坐标轴上绘制 -> 但您可以将可见性设置为关闭。
您将在下面找到如何绘制圆圈以及通过鼠标移动更新位置的示例。它可以帮助您入门...
function circleExample
f = figure;
ax = axes ( 'parent', f, 'Position', [0 0 1 1] );
% circle diameter
d = 2;
% center of circle.
c = [10 10];
% Create position of circle.
pos = [c-d/2 d d];
% Create circle via rect command.
h = rectangle('Position',pos,'Curvature',[1 1]);
% make sure its looks like a circle.
axis equal
% Update some axes properties
set ( ax, 'visible', 'off', 'XLim', [0 20], 'YLim', [0 20], 'XLimMode', 'manual', 'YLimMode', 'manual' );
% Add a callback to the figure to update the position when the circle moves
set ( f, 'WindowButtonMotionFcn', @(a,b)UpdateCirclePos ( ax, h, d ) )
end
function UpdateCirclePos ( ax, h, d )
cp = get ( ax, 'CurrentPoint' );
h.Position = [cp(1,1) cp(1,2) d d];
end
我正在制作 MATLAB 和 Ascention Trakstar(运动)传感器之间的实时接口。在此任务中,我在 MATLAB GUI 图 window(全屏尺寸)上将实时传感器位置显示为正方形。
我想在各种形状上显示传感器位置(现在关注圆形)。如何在MATLAB GUI图形中画圆window?以及如何通过MATLAB实时循环句柄?
提前致谢。
您需要在坐标轴上绘制 -> 但您可以将可见性设置为关闭。
您将在下面找到如何绘制圆圈以及通过鼠标移动更新位置的示例。它可以帮助您入门...
function circleExample
f = figure;
ax = axes ( 'parent', f, 'Position', [0 0 1 1] );
% circle diameter
d = 2;
% center of circle.
c = [10 10];
% Create position of circle.
pos = [c-d/2 d d];
% Create circle via rect command.
h = rectangle('Position',pos,'Curvature',[1 1]);
% make sure its looks like a circle.
axis equal
% Update some axes properties
set ( ax, 'visible', 'off', 'XLim', [0 20], 'YLim', [0 20], 'XLimMode', 'manual', 'YLimMode', 'manual' );
% Add a callback to the figure to update the position when the circle moves
set ( f, 'WindowButtonMotionFcn', @(a,b)UpdateCirclePos ( ax, h, d ) )
end
function UpdateCirclePos ( ax, h, d )
cp = get ( ax, 'CurrentPoint' );
h.Position = [cp(1,1) cp(1,2) d d];
end