Azzera filtri
Azzera filtri

dlmread fails to import completely numeric file ?

2 visualizzazioni (ultimi 30 giorni)
Hi,
I use dlmread to import data form xls files and it works fine all the time except that suddenly it throws error to read one particular file of the same format. The error is :-
Error using dlmread (line 138) Mismatch between file and format string. Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> ÐÏࡱá
I have checked multiple times and the file is completely numeric. I do not understand why this has to happen with only this file. I have been using this script since 3 months without issues on various occasions.
The reading code is :
files=char(fileloc(b));
dev=dlmread(files);
f_efficiency(dev,b);
where files contain the path to the selected file in string format.
I have attached the file causing the trouble. Any help is appreciated.
Best Regards, Vittal
  2 Commenti
José-Luis
José-Luis il 8 Ago 2016
How did you check? In Excel just because something looks like number does not mean it actually is.
dpb
dpb il 8 Ago 2016
And to check on Jose-Luis' hypothesis, use xlsread on the .xls file and return the numeric and the optional text outputs..."almost guar-on-teed" that the text output will include the offending portion in the file. If so, somehow a cell or multiple cells formatting in the spreadsheet has gotten set -- or perhaps there's an unintended leading single quote (') in the cell content that automagically turns into text...

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 23 Ago 2016
dlmread() does not handle Unicode at this time. Even with UTF-8, if you have any characters outside of the range that can be represented with a single byte, then you can be sure that the file contains something that dlmread() will not consider one of the valid number-forming characters. UTF-8 with Byte Order Mark is not supported even if no other characters require multiple bytes in the file.
However, csvread() and dlmread() open the file and call textscan() to handle all of the work. textscan() is fine with reading Unicode files, as long as the proper fopen() file encoding parameter will work. (Of course if it isn't obvious that the file is Unicode then you might well not think to check.)
  1 Commento
Vittal Rao
Vittal Rao il 24 Ago 2016
Using textscan() saved the day. But I wonder why only this file has this problems while the rest can be properly read with dlmread(). Anyway textscan has been implemented and it works with everyfile . Thanks.

Accedi per commentare.

Più risposte (1)

S. McBride
S. McBride il 23 Ago 2016
The file you attached is a binary XLS file. DLMREAD acts on ASCII files. Here's the beginning of your file as seen by Notepad:
ÐÏࡱá > þÿ N þÿÿÿ þÿÿÿ M ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
I am seeing very similar behavior, however, with a file that looks fine in Notepad. I had just upgraded the PC from R2008a to R2014, and don't know if that is part of the issue. The file was tab-delimited when it didn't work. The file was changed to be comma-delimited, and then it seemed to work.
  1 Commento
S. McBride
S. McBride il 23 Ago 2016
Update: It looks like my tab-delimited file may have been Unicode rather than ASCII. The working CSV file is half the size of the tab-delimited file that didn't work.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by