Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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 Commenti

Accedi per commentare.

Risposta accettata

Lisa M
Lisa M il 9 Feb 2020

Più risposte (0)

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by