필터 지우기
필터 지우기

How to repeat a prompt until a expected number is written by the user

조회 수: 2 (최근 30일)
Hugo
Hugo 2022년 4월 8일
댓글: Hugo 2022년 4월 8일
Hi,
I would like to repeat a prompt to ask if the user wants to Stand=1, Sit=2, Sleep=3, Listen to Music=4. So, an integer number from 1 to 4 is expected from the user. If the answer (variable answer1) is not one of those values, the prompt must repeat until so. Right now, I have the following code:
while (answer1~=1 && answer1~=2 && answer1~=3 && answer1~=4)
answer1=input('\n what would you like to do? Stand=1, Sit=2, Sleep=3, Listen to Music=4 \n')
end
However, it is not working for me. Any suggestions on this?
I thank you in advance,
Best regards,
Hugo

채택된 답변

Stephen23
Stephen23 2022년 4월 8일
A = 0;
while ~ismember(A,1:4)
A = input(..);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by