Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

Is it possible to use FSCANF or SSCANF to read ASCII data that contains NaNs and Infs?


Date Last Modified: Tuesday, November 17, 2009
Solution ID:   1-15M3Y
Product:   MATLAB
Reported in Release:   R11
Platform:   All Platforms
Operating System:   All OS
 

Subject:

Is it possible to use FSCANF or SSCANF to read ASCII data that contains NaNs and Infs?

Problem Description:

I would like to know if it is possible to use FSCANF or SSCANF to read ASCII data that contains a NaN's or an Inf.

Solution:

On some machines, it is possible to read data that contain NaN's and Inf's.

The following machines can read NaN's and Inf's:

Macintosh
SunOS
Solaris
IBM RS/6000
DEC Alpha/OSF (fscanf only)

The following machines cannot read NaN's and Inf's:

MS-Windows
HP
SGI

If your machine cannot read NaN's and Inf's then you will have to read in the file one line at a time and convert it to its numeric values. For example:

f = fopen('file.dat', 'rt');
tmp = fgetl(f);
fclose(f);

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page