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

조회 수: 17 (최근 30일)
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');

채택된 답변

Wan Ji
Wan Ji 2021년 8월 30일
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
Wan Ji
Wan Ji 2021년 8월 30일
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);

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by