How to error check a string for numbers?

13 Ansichten (letzte 30 Tage)
PJ
PJ am 15 Okt. 2018
Kommentiert: PJ am 15 Okt. 2018
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 Kommentare
madhan ravi
madhan ravi am 15 Okt. 2018
What should be the error check ,an example?
PJ
PJ am 15 Okt. 2018
If I enter 7 as an input, it should ask the user to enter a valid name

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 15 Okt. 2018
name = input('Please enter your name:\n', 's');
if isnan(str2double(name))
fprintf('Input is a string\n')
end
  1 Kommentar
PJ
PJ am 15 Okt. 2018
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by