i and j pass isnan test?

3 Ansichten (letzte 30 Tage)
Eathan Baumgartner
Eathan Baumgartner am 10 Aug. 2018
Kommentiert: Stephen23 am 10 Aug. 2018
I have code which extracts data from a gui entry as follows:
handles.bonusI = get(handles.bonusEB,'string');
handles.bonusI = str2double(handles.bonusI);
if isnan(handles.bonusI) == 0
Code executes
else
error displays
end
For every character I have tested that are not numbers, an error will be displayed. Except i and j. When testing handles.bonus, I both hold the value of 0.0000 + 1.0000i. I have no idea why this is, anyone got a clue?
  1 Kommentar
Stephen23
Stephen23 am 10 Aug. 2018
" I have no idea why this is, anyone got a clue?"
Because i and j both represent a perfectly valid number:

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 10 Aug. 2018
i and j, as strings in your edit text box, can be passed to str2double() as a special case, but other character strings can't unless the string is all numbers. See this demo:
>> str2double('i')
ans =
0 + 1i
>> str2double('a')
ans =
NaN

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by