need help error checking my string input.

조회 수: 2 (최근 30일)
Riley Phillips
Riley Phillips 2022년 5월 3일
댓글: Riley Phillips 2022년 5월 3일
i need to error check this code
SkaDan = 'what are you looking for today? skating or dance\n';
Ans = input(SkaDan,'s');
i need it to move on if it spelled correct but if its not then i need it to spit out the message "ERROR, what are you looking for today? skating or dance"

채택된 답변

Image Analyst
Image Analyst 2022년 5월 3일
Here's one way:
replyOK = false;
SkaDan = 'What are you looking for today? Skating or dance?\n';
while ~replyOK
reply = input(SkaDan, 's');
if strcmpi(reply, 'skating') || strcmpi(reply, 'dance')
replyOK = true; % or "break" to break out of loop
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by