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 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Image Analyst
2016년 11월 23일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Modify Image Colors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!