【问题标题】:while (left button pressed) in Matlab?在Matlab中(按下左键)?
【发布时间】:2019-04-28 10:55:57
【问题描述】:

我在 Matlab 中编写了一个绘制图形的程序。我想在按下鼠标左键时在while循环中激活它。 我该怎么做?

我用过“waitforbuttonpress”,但它只工作一次。我想要持续的表现。

while (?)

functionA(); % draws a figure with get(0, 'PointerLocation') as input. 

drawnow;
cla;
end

仅当按下鼠标左键时,图形才会随着鼠标移动而更新。

【问题讨论】:

  • 您使用的是“旧”数字还是 UIFigure?另外,这是哪个版本的 MATLAB?
  • 我用的是旧的。 Matlab 2018b。

标签: matlab mouseevent matlab-figure


【解决方案1】:

我不知道我是否理解得很好,但是如果您希望循环连续运行,您可以更改 while 条件:

while (1)
    if ~waitforbuttonpress
        functionA(); % draws a figure with get(0, 'PointerLocation') as input. 
        drawnow;
        cla;
    end
end

然后可以在while(1)循环中插入一个break条件,如:

while (1)
        if input('Exit loop?') %%exit if keyboard value is different from 0
            break;
        end
end

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-26
  • 1970-01-01
  • 2011-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多