Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Matlab中,在特定时间段内只接受一次按键_Matlab_Events_User Interface_Keypress_Figure - Fatal编程技术网

在Matlab中,在特定时间段内只接受一次按键

在Matlab中,在特定时间段内只接受一次按键,matlab,events,user-interface,keypress,figure,Matlab,Events,User Interface,Keypress,Figure,我有一个简单的GUI代码,如下所示。 这个“test_keypress”功能创建一个图形,并响应按键(空格) 现在,我想添加一个约束,使Matlab在一定时间内(比如1秒)只接受一个按键。 换句话说,如果在上一次按键后1秒内发生按键,我想拒绝它 我该怎么做 function test_keypress f = figure; set(f,'KeyPressFcn',@figInput); imshow(ones(200,200,3)); end function figInput(src

我有一个简单的GUI代码,如下所示。 这个“test_keypress”功能创建一个图形,并响应按键(空格)

现在,我想添加一个约束,使Matlab在一定时间内(比如1秒)只接受一个按键。 换句话说,如果在上一次按键后1秒内发生按键,我想拒绝它

我该怎么做

function test_keypress

f = figure;
set(f,'KeyPressFcn',@figInput);
imshow(ones(200,200,3));

end


function figInput(src,evnt)

if strcmp(evnt.Key,'space')
    imshow(rand(200,200,3));
end

end

您可以存储当前时间,并且只有在最后一次按键后至少100秒按键时,才能计算
imshow
命令

function test_keypress

f = figure;
set(f,'KeyPressFcn',@figInput);
imshow(ones(200,200,3));

%# initialize time to "now"
set(f,'userData',clock);

end


function figInput(src,evnt)

currentTime = clock;
%# get last time
lastTime = get(src,'UserData');

%# show new figure if the right key has been pressed and at least
%# 100 seconds have elapsed
if strcmp(evnt.Key,'space') && etime(lastTime,currentTime) > 100
    imshow(rand(200,200,3));
    %# also update time
    set(src,'UserData',currentTime)
end

end