【发布时间】:2017-04-15 13:13:08
【问题描述】:
我正在尝试制作 MATLAB 代码,当有图形时检测键盘的左右箭头键并记录击键。
double(get(gcf,'currentcharacter'))
我尝试了上述功能,但我认为它不是我要寻找的功能。
【问题讨论】:
我正在尝试制作 MATLAB 代码,当有图形时检测键盘的左右箭头键并记录击键。
double(get(gcf,'currentcharacter'))
我尝试了上述功能,但我认为它不是我要寻找的功能。
【问题讨论】:
你可以使用 ginput
[~,~,button]=ginput(1);
switch button
case 30 %up
case 31 %down
case 28 %left
case 29 %right
end
【讨论】:
我过去为交互式缩放和平移数字写的东西:
set(gcf,'WindowKeyPressFcn',{@KeyPressd,mean(xlim)});
在“KeyPressd.m”中:
function [ ] = KeyPressd( src,evnt,S0 )
switch evnt.Key
case 'f'
set(gca,'XLim', xlim + range(xlim)/100 );
case 'v'
set(gca,'XLim', xlim - range(xlim)/100 );
case 'h'
set(gca,'YLim', ylim + range(ylim)/100 );
case 'n'
set(gca,'YLim', ylim - range(ylim)/100 );
case 'g'
set(gca,'ZLim', zlim + range(zlim)/100 );
case 'b'
set(gca,'ZLim', zlim - range(zlim)/100 );
case 'd'
set(gca,'XLim', xlim - 0.02*(xlim-sum(xlim)/2) );
case 'c'
set(gca,'XLim', xlim + 0.02*(xlim-sum(xlim)/2) );
case 'a'
set(gca,'YLim', ylim - 0.02*(ylim-sum(ylim)/2) );
case 'z'
set(gca,'YLim', ylim + 0.02*(ylim-sum(ylim)/2) );
case 's'
set(gca,'ZLim', 0.98*(zlim) );
case 'x'
set(gca,'ZLim', 1/0.98*(zlim) );
end
set(gca,'ZTickLabel',sprintf('%1.0f\n',get(gca,'ZTick')));
【讨论】: