如何使用箭头键更改某些内容的值?

时间:2016-10-20 18:15:12

标签: matlab

我创建了d = 20的值。每当我按下右箭头键时,我希望d增加10,每次按下左箭头键时减少d = 30。所以,如果我按下右箭头键一次d = 40,如果我再次按下右箭头键,则d = 30。然后,如果我按下左箭头键,然后WindowPressKeyFcn

我应该使用 {% with operations.type as type %} {{ models.{{type}} }} <!-- HOW DO I DO THIS? --> {% endwith %} 吗?

1 个答案:

答案 0 :(得分:0)

d = 20;

f = figure;
k=1;
while k
    waitforbuttonpress;
    if get(gcf,'CurrentCharacter')==28     % Detection for left key
        d=d-10
    elseif get(gcf,'CurrentCharacter')==29 % Detection for right key
        d=d+10

    elseif get(gcf,'CurrentCharacter')==32
        k=0;   % Stop execution if Spacebar is pressed
    end
end
close(f)   %Closing the figure window

This will open a figure window. Press or keys to increase or decrease the value by 10 respectively. The execution will stop if you press Spacebar .

P.S: Your figure window should always be on focus.