필터 지우기
필터 지우기

Character input error message !!

조회 수: 2 (최근 30일)
Mohamed Djama
Mohamed Djama 2015년 3월 21일
답변: Giorgos Papakonstantinou 2015년 3월 21일
Hello there, i want my inputs to be a positive number not a negative number or a text just positive number starting from zero, therefore i used this code,
m = str2num(get(handles.m,'string'));
v = str2num(get(handles.v,'string'));
if ( m >= 0 && v >= 0)
else
errordlg( 'The Inputs must be a positive numbers' )
end
This error is only for the negative values, i want to add if the input is text show an error so what should i add to this code .

답변 (1개)

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2015년 3월 21일
If the string you get from handles.m is a char class then str2num will produce an empty matrix.
>> str2num('hello')
ans =
[]
Therefore, your else statement will be invoked and apparently, you will not have a problem. However, if you want to determine whether the item is character array you may use ischar.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by