查看图形时在matlab中检测击键?
我试图在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
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
属性,但它不会让您知道实际按下键的时间