any function like kbhit

12 ビュー (過去 30 日間)
gang gyoo jin
gang gyoo jin 2016 年 6 月 24 日
編集済み: armando herculano 2024 年 4 月 1 日
Hi all Is there any function like kbhit(in C) in matlab. I want to use that function inside the for loop to terminate the loop. Thanks in advance
for i=1:100000
if kbhit == 'q'
break;
end
end

採用された回答

Walter Roberson
Walter Roberson 2016 年 6 月 24 日
  1 件のコメント
Andrew Diamond
Andrew Diamond 2018 年 12 月 8 日
kbhit oesn't seem to work in Matlab 2017b. I get this error message:
Error using set
The name 'Userdata' is not an accessible property for an instance of class
'com.mathworks.mde.cmdwin.CmdWin'.
That occurs in the init, i.e. kbhit('init') in:
set(KBHIT_h_cw, 'userdata', []);
I don't see a property method/accessor for "userdata"

サインインしてコメントする。

その他の回答 (3 件)

Bin Yang
Bin Yang 2019 年 11 月 21 日
Replace your kbhit.m with the one attached here, it should work. The original version tried to store key event data in the 'Userdata' property of the command window object, however it is no longer viable in later Matlab versions. What I did was just to asign key event data directly to a global variable.

gang gyoo jin
gang gyoo jin 2016 年 6 月 24 日
Many thanks. It works.

armando herculano
armando herculano 2024 年 4 月 1 日
編集済み: armando herculano 2024 年 4 月 1 日
for MATLAB:
while true
ch = getkey
if ch != 165 break; end
end
----------------------
for OCTAVE
while true
if kbhit(1) break; end
end
-----------------------------
while true
% 165 ASCII code for null
if kbhit(1) != 165 break end
end
--------------------------------------

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by