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

3 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

采纳的回答

Lisa M
Lisa M 2020-2-9

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by