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

2 ビュー (過去 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 Center および File ExchangeModify Image Colors についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by