在MATLAB GUI中圈出

时间:2015-04-14 10:17:24

标签: matlab user-interface matlab-guide

我在MATLAB和Ascention Trakstar(运动)传感器之间建立了实时接口。在这个任务中,我在MATLAB GUI图形窗口(屏幕全尺寸)上将实时传感器位置显示为正方形。

我想在各种形状上显示传感器位置(现在专注于圆圈)。如何在MATLAB GUI图窗口中绘制一个圆?以及如何通过MATLAB实时循环处理?

谢谢你。

1 个答案:

答案 0 :(得分:0)

你需要画一个轴 - >但您可以将可见性设置为关闭。

下面你会看到一个如何通过鼠标移动绘制圆圈和更新位置的示例。它可以让你开始......

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