gpt4 book ai didi

Matlab 循环直到击键

转载 作者:行者123 更新时间:2023-12-02 09:31:44 25 4
gpt4 key购买 nike

我有一个循环,其中我不断使用 ginput 将点输入到图中。我希望循环运行直到用户按下一个键,这就是我所拥有的:

function enter_points()
f = figure();
axis([-1 1 -1 1]);

coorX = [];
coorY = [];

while 1
[x, y] = ginput(1);
coorX = [coorX x];
coorY = [coorY y];

waitforbuttonpress;
key = get(f,'CurrentCharacter');
if (key == 'e')
display('End of cycle.')
break;
else
display('Enter next point')
end
end

coor = [transpose(coorX) transpose(coorY)];
display(size(coor));
display(coor);
end

这段代码的问题是,我必须按一个键才能继续输入点。另一个问题是,Matlab 在运行此代码时有时会卡住(我不确定是代码原因还是其他原因)。如何检测按“enter”而不是“e”?感谢您的帮助

最佳答案

为什么不使用内置的:

[X,Y] = ginput gathers an unlimited number of points until the return key is pressed.

关于Matlab 循环直到击键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13357970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com