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 で Object Containers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!