フィルターのクリア

I am attempting to only allow users to respond using the 'j' key or the 'k' key. For some reason MATLAB doesn't allow users to respond using the 'k' key. Instead it displays the error that "'k' is an undefined function or variable"

1 回表示 (過去 30 日間)
Kyle Davis
Kyle Davis 2019 年 1 月 25 日
編集済み: madhan ravi 2019 年 1 月 28 日
I have the following code; it allows users to respond using the 'j' key but unfortunately not the 'k' key.
f=figure(1);
for i=1:21
imshow(all_images{i});
shg;
txt=sprintf('%d/%d: Was the consonent shown the same as N before?:', i, N);
response= input(txt);
if response== j|| response== k
continue
else
disp('Letter pressed is not accepted')
end
fprintf(fid, 'stimuli: %d/t response: %s/n', i, response);
fclose(fid);
end
Thank you for your help.

回答 (1 件)

madhan ravi
madhan ravi 2019 年 1 月 25 日
response=input(txt,'s')
% ^^^---- missed it
doc input % read what 's' does
Note: See when you enter j you don't get an error because matlab interprets j as an imaginary unit.
Further on while comparing characters use strcmp().
  5 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 25 日
Thank you sir Walter and Guillaume for narrowing it further!
Kyle Davis
Kyle Davis 2019 年 1 月 25 日
編集済み: madhan ravi 2019 年 1 月 28 日
Thank you everyone for your help, I really appreciate it, I understand where I was going wrong now!

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by