フィルターのクリア

Limiting number of characters to three positions (ranging from 0–100)

3 ビュー (過去 30 日間)
Lisa M
Lisa M 2020 年 2 月 9 日
回答済み: Lisa M 2020 年 2 月 9 日
So far the code restricts character responses to keys 0-9. However you could type 300. I would like to limit the response in a way that only 0–100 responses are possible. Any suggestions? Thanks in advance.
string = '';
while true
% assemble the cue/target display
output = [msg, ' ', string];
% show it
Screen('CopyWindow',origwindow, windowPtr);
Screen('DrawText', windowPtr, output, x, y, textColor, bgColor);
Screen('Flip', windowPtr,0);
char = GetChar;
switch (abs(char))
case {13, 3, 10}
% ctrl-C, enter, or return
return;
case 8
% backspace
if ~isempty(string)
string = string(1:length(string)-1);
end
% 0-9
case {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58}
string = [string, char];
end
end
  4 件のコメント
Walter Roberson
Walter Roberson 2020 年 2 月 9 日
Change my <= 2 into <= 1
Lisa M
Lisa M 2020 年 2 月 9 日
Thanks!! It works.

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

採用された回答

Lisa M
Lisa M 2020 年 2 月 9 日

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by