import problem with CSV file
16 ビュー (過去 30 日間)
古いコメントを表示
I am having trouble importing CSV files that are output by a spectrometer system I am using. I can't figure out what is wrong with the file but routines I had written awhile ago using the commandline 'csvread' function. I also tried the commandline 'importdata' function which sort of works but doesn't read the file properly either. It appears like both are encountering some odd characters, "", at the beginning of the file. I have opened up several of these trouble CSV files in Excel, Word, Wordpad and Notepad (as CSV files or after changing the extension to TXT) and don't see any problems in any of those programs. Additionally, if I click on the "Import Data" button in the Home tab of matlab and select one of these files it seems to have no issues and interprets the file as expected. Below is the output I get using the commandline 'importdata' and 'csvread' read functions where the odd characters can be seen. I've attached one of the CSV files as an example. I am running Win 7 and Matlab R2017a. Any help would be appreciated.
Thanks, Aaron
>> data = importdata('test.csv');
>> data
data =
struct with fields:
data: [1340×3 double]
textdata: {1340×1 cell}
rowheaders: {1340×1 cell}
>> data.rowheaders{1}
ans =
'1'
>> data = csvread('test.csv');
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==>
1,523.73748068959833,0,1\n
Error in csvread (line 48)
m=dlmread(filename, ',', r, c);
0 件のコメント
回答 (1 件)
Jan
2018 年 3 月 16 日
The "" is a "BOM", a Byte Order Mark. This is required for UTF files. When I open the attached file, I do not see such a BOM and therefore I cannot reproduce your problem. The solution is to remove it by recreating the files. You can import the contents by fileread or fread, remove the BOM and write the data back to the disk.
By the way, if I ask an internet search engine for "", I get equivalent answers. It is recommended to search before asking.
2 件のコメント
Noam Greenboim
2020 年 5 月 21 日
For removing BOM, you can easily use this function (see link below):
BOM('test.csv','')
参考
カテゴリ
Help Center および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!