Info

この質問は閉じられています。 編集または回答するには再度開いてください。

For loop not executing

1 回表示 (過去 30 日間)
NAMRATA SINGH
NAMRATA SINGH 2016 年 11 月 26 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello ,
I am trying to run this for loop and again it stops at section four where it displays letters 'L P E D' but after that it is stuck without any error message.
for i = 1:8
if i == 1
j = 'E';
figure('units','normalized', 'outerposition',[0 0 1 1], 'color', [1 1 1 1])
axis off
text(.45, .6, 'E', 'fontname', 'Times', 'fontsize', 200)
pause
LetterOne = input('What letter did you see on the screen?', 's')
LetterOne = upper(LetterOne)
return_value = strcmp(j,LetterOne)
if return_value == 1,
disp ' Press a key to continue'
else return_value == 0,
disp('Thank you participating in the vision test.')
disp('Your vision is 20/200');
break
end
clf
end
if i == 2
j = 'F P';
figure('units','normalized', 'outerposition',[0 0 1 1], 'color', [1 1 1 1])
axis off
text(.40, .6, 'F P', 'fontname', 'Times', 'fontsize', 100)
pause
LetterTwo = input('What letter did you see on the screen?', 's')
LetterTwo = upper(LetterTwo)
return_value = strcmp(j,LetterTwo)
if return_value == 1,
disp ' Press a key to continue'
else return_value == 0,
disp('Thank you participating in the vision test.')
disp('Your vision is 20/100');
break
end
clf
end
if i == 3
j = 'T O Z';
figure('units','normalized', 'outerposition',[0 0 1 1], 'color', [1 1 1 1])
axis off
text(.45, .6, 'T O Z', 'fontname', 'Times', 'fontsize', 70)
pause
LetterThree = input('What letter did you see on the screen?', 's')
LetterThree = upper(LetterThree)
return_value = strcmp(j,LetterThree)
if return_value == 1,
disp ' Press a key to continue'
else return_value == 0,
disp('Thank you participating in the vision test.')
disp('Your vision is 20/70');
break
end
clf,close
end
if i == 4
j = 'L P E D';
figure('units','normalized', 'outerposition',[0 0 1 1], 'color', [1 1 1 1])
axis off
text(.45, .6, 'L P E D', 'fontname', 'Times', 'fontsize', 50)
pause
LetterFour = input('What letter did you see on the screen?', 's')
LetterFour = upper(LetterFour)
return_value = strcmp(j,LetterFour)
if return_value == 1,
disp ' Press a key to continue'
else return_value == 0,
disp('Thank you participating in the vision test.')
disp('Your vision is 20/50');
break
end
clf, close
end
if i == 5
j = 'P E C F D';
figure('units','normalized', 'outerposition',[0 0 1 1], 'color', [1 1 1 1])
axis off
text(.35, .6, 'P E C F D', 'fontname', 'Times', 'fontsize', 40)
pause
LetterFive = input('What letter did you see on the screen?', 's')
LetterFive = upper(LetterFive)
return_value = strcmp(j,LetterFive)
if return_value == 1,
disp ' Press a key to continue'
else return_value == 0,
disp('Thank you participating in the vision test.')
disp('Your vision is 20/40');
break
end
clf, close all
end
if i == 6
j = 'E D P C F Z';
figure('units','normalized', 'outerposition',[0 0 1 1], 'color', [1 1 1 1])
axis off
text(.40, .6, 'E D P C F Z', 'fontname', 'Times', 'fontsize', 30)
pause
LetterSix = input('What letter did you see on the screen?', 's')
LetterSix = upper(LetterSix)
return_value = strcmp(j,LetterSix)
if return_value == 1,
disp ' Press a key to continue'
else return_value == 0,
disp('Thank you participating in the vision test.')
disp('Your vision is 20/30');
break
end
clf, close
end
if i == 7
j = 'F E L O P Z D';
figure('units','normalized', 'outerposition',[0 0 1 1], 'color', [1 1 1 1])
axis off
text(.45, .55, 'F E L O P Z D', 'fontname', 'Times', 'fontsize', 25)
pause
LetterSeven = input('What letter did you see on the screen?', 's')
LetterSeven = upper(LetterSeven)
return_value = strcmp(j,LetterSeven)
if return_value == 1,
disp ' Press a key to continue'
else return_value == 0,
disp('Thank you participating in the vision test.')
disp('Your vision is 20/25');
break
end
clf, close
end
if i == 8
j = 'D E F P O T E C';
figure('units','normalized', 'outerposition',[0 0 1 1], 'color', [1 1 1 1])
axis off
text(.45, .6, 'D E F P O T E C', 'fontname', 'Times', 'fontsize', 20)
pause
LetterEight = input('What letter did you see on the screen?', 's')
LetterEight = upper(LetterEight)
return_value = strcmp(j,LetterEight)
if return_value == 1,
disp ' Press a key to continue'
else return_value == 0,
disp('Thank you participating in the vision test.')
disp('Your vision is 20/20');
break
end
clf, close
end
end

回答 (2 件)

Image Analyst
Image Analyst 2016 年 11 月 26 日
We'd have to step through this long program with the debugger, just like you. I think you should be able to do it as well as us. If you don't know how to do it, see this nice tutorial: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/

Walter Roberson
Walter Roberson 2016 年 11 月 26 日
Your "close all" is probably interfering
Instead of using close like that, you should be recording the handle returned from figure() and close() that specific handle.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by