点在Matlab中从一个角落移动到另一个角落围绕监视器

问题描述

我正在尝试创建一个球或点或从左下角到右下角,然后是右上角,然后是左上角,然后是起点的任何东西。基本上在屏幕周围。而且在全屏模式下那很重要。对于全屏图形,我正在使用WindowAPI。

这是我的代码

try
   % Create a figure to operate on: --------------------------------------------
   % The OpenGL renderer is confused by the alpha blending,so Painters is used:
   figH   = figure('Color',ones(1,3),'Renderer','Painters');
   axes('Visible','off','Units','normalized','Position',[0,1,1]);
   % Set topmost status:
   WindowAPI(figH,'topmost');   % Command is not case-sensitive
   drawNow;
   WindowAPI(figH,'TopMost',0);
   drawNow;
   WindowAPI(figH,'front');
   drawNow;
   
   % Nicer to have the figure on topmost for the rest of the demo:
   WindowAPI(figH,'topmost');
   
   % Special maximizing such that the inner figure fill the screen:
   WindowAPI(figH,'full');  % Complete monitor
   
    % START MOVING BALL

X = 2;
Y = 0;
for i=1:1490
    X = X + 0.1;
    Y = 2
    plot(X,Y,'or','MarkerSize',20,'MarkerFaceColor','r')
    axis([0 151 0 85])  
    pause(0)
end
   % END MOVING BALL
   
end

enter image description here

为简单起见,点仅从左下角到右下角。 但是有两个问题。

  1. 有时候点滞后是一个问题。
  2. (从图中)有可见的黑线。

我不知道如何解决这两个问题。因此,如果您知道如何修复它们或以任何更好的方式在Matlab中为球设置动画,请在此处发布。谢谢您的时间。

解决方法

要减少“滞后”量,您可以执行以下操作:

  1. 将绘图线移动到循环的外部,并将其分配给手柄,另外将轴突击移动到一起

    pH = plot(X,Y,'or','MarkerSize',20,'MarkerFaceColor','r');
    axis([0 151 0 85])  
    axis off
    

    现在您可以直接在循环中更新X Y数据。

    set(pH,'XData',X,'YData',Y)
    
  2. 将暂停替换为(将延迟帧的秒数长度替换为0):

    tic;while toc<0;end
    

    这更快,更精确,并且不会导致MatLab中断。

  3. 在循环中添加drawnow命令以使图形更新。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...