I want to throw the error that comes with entering a non number in a numeric only input

18 visualizaciones (últimos 30 días)
n = input('Please enter a number:\n');
I get this error and I want to throw it and write another error:
Error using input
Unrecognized function or variable 'k'.
Error in eer (line 1)
n = input('Please enter your name:\n');

Respuesta aceptada

Wan Ji
Wan Ji el 30 de Ag. de 2021
n = str2num(input('Please enter a number:\n','s'));
if(isempty(n))
error('You are entering a non number in a numeric only input')
end
  10 comentarios
Wan Ji
Wan Ji el 30 de Ag. de 2021
n = input('Please enter a number:\n','s');
if(isempty(n))
error('You are entering nothing')
elseif(isempty(str2num(n)))
error('You are entering a non number in a numeric only input')
end
n = str2num(n);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Argument Definitions en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by