use any/all test with while loop in range 0:1:10

I do have a vector of quiz grade(which input by reader). the valid grades are in the range of 0:1:10. I have to use any/all test in a while loop
grades = input('Please enter the vector of your grades:')
A = [0:1:10];
while any(grades > A) ~= 1
disp('Please enter the correct vector of your grades')
grades = input('Please enter the vector of your grades:')
end
disp(strrep(['Your grade is: (' num2str(grades, ' %d,') ')'], ',)', ')'))
When I put a input which over the range, it still did not disp that I enter a wrong vector . Is that any part I should fix up?

 採用された回答

pietro
pietro 2014 年 11 月 11 日
編集済み: pietro 2014 年 11 月 11 日

0 投票

Hi,
while loops until the condition is true, so you to change looping condition:
grades = input('Please enter the vector of your grades:')
while any(grades<0 | grades>10) == 1
disp('Please enter the correct vector of your grades')
grades = input('Please enter the vector of your grades:')
end
disp(strrep(['Your grade is: (' num2str(grades, ' %d,') ')'], ',)', ')'))

3 件のコメント

jarvan
jarvan 2014 年 11 月 11 日
when I put in 12 or any number bigger than 10, it still did not disp that I enter a wrong vector.
pietro
pietro 2014 年 11 月 11 日
I have edited the answer
jarvan
jarvan 2014 年 11 月 11 日
it works now..thank you

サインインしてコメントする。

その他の回答 (1 件)

MA
MA 2014 年 11 月 11 日

0 投票

try this
clear all
clc;
grades = input('Please enter the vector of your grades:')
A =[0:1:10];
while grades > A
disp('Please enter the correct vector of your grades')
grades = input('Please enter the vector of your grades:')
end
disp(strrep(['Your grade is: (' num2str(grades, ' %d,') ')'], ',)', ')'))

1 件のコメント

jarvan
jarvan 2014 年 11 月 11 日
I have to use any/all in this problem

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeAutomotive についてさらに検索

タグ

質問済み:

2014 年 11 月 11 日

コメント済み:

2014 年 11 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by