Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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_User Interface_Keyboard - Fatal编程技术网

查看图形时在matlab中检测击键?

查看图形时在matlab中检测击键?,matlab,user-interface,keyboard,Matlab,User Interface,Keyboard,我试图在matlab中对一些图像数据进行排序,并希望提示用户输入一系列图像。每次显示图像时,我都想暂停并等待击键,然后根据按下的内容执行不同的操作 当前最佳解决方案: responses = zeros(length(images),1); for i = 1:length(images) im = imread(images{i}.fname); h = figure(1); imshow(im); % instead of just pause, I wan

我试图在matlab中对一些图像数据进行排序,并希望提示用户输入一系列图像。每次显示图像时,我都想暂停并等待击键,然后根据按下的内容执行不同的操作

当前最佳解决方案:

responses = zeros(length(images),1);
for i = 1:length(images)
    im = imread(images{i}.fname);
    h = figure(1);
    imshow(im);

    % instead of just pause, I want to get the keystroke (k) that was pressed
    waitforbuttonpress;
    k = get(h,'CurrentCharacter');

    switch lower(k)
        case 'a'
            responses(i) = 1;
        case 'b'
            responses(i) = 2;
    end

end

您可以使用figure环境的
KeyPressFcn
属性,该属性应设置为接收包含按下字符的事件结构的回调函数句柄。有关详细信息和示例,请参见

此外,您还可以查看图形环境的
CurrentKey
属性,但它不会让您知道实际按下键的时间