【问题标题】:Dot moves from corner to corner (around monitor) in matlab点在matlab中从一个角落移动到另一个角落(围绕显示器)
【发布时间】:2021-02-02 00:34:59
【问题描述】:

我正在尝试创建一个球或点或任何从左下角到右下角然后右上角然后左上角然后在开始左下角的东西。基本上围绕屏幕。总的来说,全屏很重要。对于全屏图形,我使用的是 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, 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, 'Position', '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

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

  1. 点滞后有时是个问题。
  2. 有可见的黑线(来自图表)。

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

【问题讨论】:

  • axis off 添加到末尾,在pause(0) 之前。滞后是不可避免的,MATLAB 不是实时渲染器
  • @AnderBiguri 谢谢。如果我可能会问有没有其他方法可以在没有滞后的情况下在 matlab 中做到这一点?当然,据你所知。
  • 购买一台具有更多 RAM 和 GPU 的更好的计算机.... MATLAB 不是实时渲染器,它不是为此而设计的。为什么需要它?
  • 谢谢。我可能会尝试团结。
  • 当然,MATLAB 和 Unity 之间的常见用例为零。如果 Unity 是一个选项,那么 MATLAB 不应该是....

标签: matlab graph eye-tracking


【解决方案1】:

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

  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 命令以更新数字。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-16
    • 2020-08-22
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2018-05-19
    相关资源
    最近更新 更多