I am trying to run a while loop for simulation of test on the computer and it stops at the second if loop stating that it is busy
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clear all
close all
clc
Letters=[]
while j<9
if j<1
i = 'E';
set (figure, 'color', [1 1 1])
figure(1)
clf,text(.45, .6, 'E', 'fontname', 'Times', 'fontsize', 200)
axis off
pause
LetterOne = input('What letter did you see on the screen?', 's')
LetterOne = upper(LetterOne)
if char(i) == char(LetterOne)
disp('Press a key to continue')
else disp('Thank you participating in the vision test.')
disp('Your vision is 20/200');
return
end
end
if j<2
i= 'F P';
set (figure, 'color', [1 1 1])
figure(2)
clf,text(.40, .6, 'F P', 'fontname', 'Times', 'fontsize', 100)
axis off
pause
LetterTwo = input('What letter did you see on the screen?', 's')
LetterTwo = upper(LetterTwo)
if char(i) == char(LetterTwo)
disp('Press a key to continue')
else disp('Thank you participating in the vision test.')
disp('Your vision is 20/100')
return
end
end
if j<3
i = 'T O Z';
set (figure, 'color', [1 1 1])
figure(3)
clf,text(.35, .6, 'T O Z', 'fontname', 'Times', 'fontsize', 70)
axis off;
pause
LetterThree = input('What letter did you see on the screen?', 's')
LetterThree = upper(LetterThree)
if char(i)== char(LetterThree)
disp('Press a key to continue')
else disp('Thank you participating in the vision test.')
disp('Your vision is 20/70');
return
end
clf
end
end
Individually the code runs in sections but not as a whole
0 commentaires
Réponses (2)
Image Analyst
le 23 Nov 2016
When you do
if char(i) == char(LetterOne)
the badly-named "i" is already a character so there is no need to cast it to char. Next, don't compare strings like that. Use strcmpi() instead. Third, use isempty() to check if the user simply hit enter instead of characters and take appropriate action (warn them, or exit, or whatever). Fourth, you should remove white space in case users put spaces between the letters:
if ~isempty(LetterTwo)
LetterTwo(LetterTwo == ' ') = []; % Remove spaces.
So keep at it. Try those things and let us know if you have any further problems.
0 commentaires
Voir également
Catégories
En savoir plus sur Object Containers dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!