The function textscan breaks when there is a -NaN in the input string or input file. I expect MATLAB to return NaN when a -NaN is in the field (as it does for NaN), but it returns an empty value.
Expected Behavior: The proper result happens when reading a 'NaN' from a string or file:
>> a = textscan('NaN','%f') a = [NaN]
An empty value is returned when the string or input file contains '-NaN':
>> a = textscan('-NaN','%f') a = [0x1 double]
This cannot be remedied using the 'TreatAsEmpty' option, because MATLAB recognises '-NaN' as a numeric value:
>> a = textscan('-NaN','%f','TreatAsEmpty','-NaN') ??? Error using ==> textscan TreatAsEmpty strings cannot be numeric.
Best Answer