필터 지우기
필터 지우기

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

답변 (2개)

Image Analyst
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.

NAMRATA SINGH
NAMRATA SINGH 2016년 11월 23일
Thank you for your reply image analyst. I am confused on how to address your third suggestion- 'Third, use isempty() to check if the user simply hit enter instead of characters and take appropriate action (warn them, or exit, or whatever).' How can I do it in the if statement?
Thank you, Namrata

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by