Problem using 'getkey'.

6 次查看(过去 30 天)
For some reason 'getkey' is not working in Matlab R2014a. It keeps saying 'undefined function/variable' whenever I use getkey. Can anyone tell me what to do?
clear all;
clc;
fprintf('\nPress any key: ') ;
% prompt='Enter any key';
%ch=input(prompt);
k=getkey;
answer=1;
arduino=serial('COM15','BaudRate',9600); % create serial communication object on port COM15
fopen(arduino); % initiate arduino communication
while(answer)
fprintf(arduino,'%s',char(k)); % send answer variable content to arduino
answer=input('Enter value(0=EXIT PROGRAM): ');
end
fclose(arduino); % end communication with arduino

采纳的回答

Geoff Hayes
Geoff Hayes 2015-9-27
The error message
Undefined function or variable 'getkey'.
is telling you that MATLAB can't find the function getkey within the MATLAB search path. Is this a function that you have written or have downloaded from somewhere?
You may want to check the submission from Jos (10584) to the MATLAB File Exchange which can be found at http://www.mathworks.com/matlabcentral/fileexchange/7465-getkey. You will need to download this code and place it within your MATLAB search path.
  2 个评论
Em_23
Em_23 2015-9-28
Thank you so much. It's working now!! :)
armando herculano
k=getkey, o que não é uma função padrão em MATLAB. Se você estiver tentando capturar a tecla pressionada pelo usuário, você pode usar a função pause junto com a função getch (ou getch no Windows).
esta função getkey é específica para o sistema operacional Windows.

请先登录,再进行评论。

更多回答(1 个)

MathWorks MATLAB Hardware Team
Hello,
Thank you for contacting us.
To enhance your experience interfacing Arduino with MATLAB, we suggest utilizing the MATLAB Support Package for Arduino hardware. You can find more information here: https://in.mathworks.com/matlabcentral/fileexchange/47522-matlab-support-package-for-arduino-hardware
Best regards,
MATLAB Hardware Team
MathWorks

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by