【问题标题】:Matlab get() function not correctly getting key pressedMatlab get()函数没有正确按下按键
【发布时间】:2021-06-17 22:47:12
【问题描述】:

我正在根据气船设计在以下位置进行船模拟: https://github.com/cmontalvo251/MATLAB/tree/5002bcd426ab31fb882442e75eb3ad567b020a22/Boat

但是当我运行这个脚本并按下任意箭头键时,光标会跳转到命令窗口并且没有输入到脚本中。

function keypress(varargin)
global uk

%%%uk = [dt,dr];

key = get(gcbf,'CurrentKey');

switch key
    %%%Increase Thrust
 case 'uparrow'
  uk(1) = uk(1) + 1;
  if uk(1) > 100
      uk(1) = 100;
  end
  %%%%Decrease Thrust
 case 'downarrow'
  uk(1) = uk(1) - 1;
  if uk(1) < 0
      uk(1) = 0;
  end
  %%%%Turn Left? 
 case 'leftarrow'
  uk(2) = uk(2) + 0.1;
  if uk(2) > 30*pi/180
      uk(2) = 30*pi/180;
  end
  %%%%Turn Right?
 case 'rightarrow'
  uk(2) = uk(2) - 0.1;
  if uk(2) < -30*pi/180;
      uk(2) = -30*pi/180;
  end
end

这是 MatLab 的问题吗?我观看了有关脚本如何工作的视频,但我的模拟运行不一样。

https://www.youtube.com/watch?v=NT9vEOMm6vM&ab_channel=MonteCarlos

【问题讨论】:

    标签: matlab simulation game-physics


    【解决方案1】:

    似乎我所要做的就是在命令窗口中按回车键并重新打开图表。模拟运行 200 秒,也可以更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-18
      • 2016-02-18
      相关资源
      最近更新 更多