Declaration of Variables

Does adding "Num" to a variable ensure that variable input from the user is a number?

댓글 수: 1

the cyclist
the cyclist 2011년 10월 6일
I am not sure what you mean by "adding Num". Can you give an example of your syntax?
Are you talking about keyboard input [e.g the input() function]? That is going to be a string, and you need to convert to a number and put in safeguards for the input.

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

답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 10월 6일

0 개 추천

No. It does not. If the input is a string you could convert it to a number and check and see e.g.
x = '3';
is_x_a_number = isnan(str2double(x))
Then if x can't be converted it'll fail, try:
x = 'hello world'

카테고리

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

제품

질문:

2011년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by