Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
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 Kommentare

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Lisa M
Lisa M am 9 Feb. 2020

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by