我在Matlab中编写了一个绘制图形的程序。我想在按下鼠标左键时在while循环中激活它。我怎样才能做到这一点?
我使用过“waitforbuttonpress”,但它只运行一次。我想要持续的表现。
while (?)
functionA(); % draws a figure with get(0, 'PointerLocation') as input.
drawnow;
cla;
end
只有在按下鼠标左键时,图形才会随鼠标移动而更新。
我不知道我是否理解得很好,但如果你想让你的循环连续运行,你可以改变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