Problem by importing alpha numeric text files

Hi,
INTRO:
I have an alpha numeric text file. Thus, among many values, I have
also the output 'NA' for non available value of a given row and
column number.
PROBLEM:
I don't know how to load this type of table. It seems that Matlab
matrices can't include alphanumeric quantities.
I used the command line:
X=load('X.txt');
and it always returns the
error:
??? Error using ==> load Unknown text on line number 1 of ASCII file
QUESTION:
I wounder if someone knows what I have to change to load the matrix
as original and still be able to perform calculations with it.
I don't want to substitute 'NA' by zero because I don't want that
the value zero be included in further statistical calculations, such
as median, etc...
Thank you,
Emerson

 Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 28 Aug. 2011

0 Stimmen

fid = fopen('c:\myfile.txt');
data = textscan(fid,'format','TreatAsEmpty','NA','EmptyValue',NaN);
fclose(fid);

3 Kommentare

Emerson De Souza
Emerson De Souza am 28 Aug. 2011
Hi Oleg,
thank you for your help.
I followed your suggestion above for the file test.txt as below:
7 146 3 1.8 48. 60.
7 147 3 2.1 153. 512.5
7 148 0 NA NA NA
7 149 0 NA NA NA
7 150 6 -2.2 101.5 55.
but I obtain the error:
??? Error using ==> format
Too many output arguments.
I'm trying to fix but did not solve yet
Oleg Komarov
Oleg Komarov am 28 Aug. 2011
You have to insert a valid format as explained in the documentation (see link).
In your case
fmt = '%f%f%f%f%f%f';
textscan(fid,fmt,...)
Emerson De Souza
Emerson De Souza am 28 Aug. 2011
Thank you a lot Oleg!
Problem is fixed by your suggestions.
Wish you a nice day
Emerson

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by