How to error check a string for numbers?

So I have an input
name = input('Please enter your name:\n', 's');
How can I error check so that a user cannot enter any numbers for it?

댓글 수: 2

madhan ravi
madhan ravi 2018년 10월 15일
What should be the error check ,an example?
PJ
PJ 2018년 10월 15일
If I enter 7 as an input, it should ask the user to enter a valid name

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2018년 10월 15일

0 개 추천

name = input('Please enter your name:\n', 's');
if isnan(str2double(name))
fprintf('Input is a string\n')
end

댓글 수: 1

PJ
PJ 2018년 10월 15일
This gives me an error now if I enter a name but it gives me a go if I enter a number. I need it to do the opposite.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

질문:

PJ
2018년 10월 15일

댓글:

PJ
2018년 10월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by