I am Trying the following sequence:
kbinput = input( ' ' );
if ischar(next)
error('invalid string - ' );
fprintf('....');
which expects a number
typing a character instead of a number I get this
Error using input Undefined function or variable 't'.
Error in dataplot (line 16)

댓글 수: 1

KSSV
KSSV 2016년 3월 16일
clc; clear all ;
kbinput = input( ' ' );
if ischar(kbinput)
error('invalid string - ' );
fprintf('....');
end
is the code? What you want to do actually?

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

 채택된 답변

Guillaume
Guillaume 2016년 3월 16일

0 개 추천

By default, input interprets the user input as a matlab expression and evaluates it. If the user input is not a valid matlab expression then it returns an error.
If you want the user to be able to enter something that is not a matlab expression, then you need to pass the 's' option to input:
kbinput = input(' ', 's'); %and please use a prompt rather than an empty string
All input (including numbers) is then interpreted as text. If on the next line you meant to test that kbinput is char (instead of the undefined variable next), then the test will always return true. If you want to make sure that the input is truly a number:
kbinput = input(' ', 's');
numericvalue = str2double(kbinput);
if isnan(numericvalue)
error('you did not enter a number');
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

질문:

2016년 3월 16일

답변:

2016년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by