dlmread with ^ as delimiter

2 次查看(过去 30 天)
wesso Dadoyan
wesso Dadoyan 2015-6-28
编辑: dpb 2015-6-28
Hi, Attached a text file where the ^ delimiter works well to import it to excel. The automatic import tab in matlab is failing to import it . I tried also the dlmread function using '^' as a delimiter but it didn't work. Any help is appreciated
  4 个评论
wesso Dadoyan
wesso Dadoyan 2015-6-28
I reattached the file.sorry for the inconvenience
wesso Dadoyan
wesso Dadoyan 2015-6-28
编辑:dpb 2015-6-28
for example using dlmread('bhcf0003.txt','^') led to the following error:
Error using dlmread (line 138)
Mismatch between file and format string.
Trouble reading number from file (row 1u, field 1u) ==>
rssd9999^rssd9001^BHCK0081^BHCK0395^BHCK0397^BHCK1350^BHCK2122^BHCK3123^BHCK3128^BHCK2125^BHCK2145^BHCK2150^BHCK2130^BHCK2155^BHCK3164^BHCK3163^BHCK2160^BHCK2170^BHDM6631^BHDM6636^BHFN6631^BHFN6636^BH
Error in Step1ReadCallReports (line 2)
dlmread('bhcf0003.txt','^')
also the automatic import didn't have the desired values (look at the difference between excel and matlab and the attached snapshots)

请先登录,再进行评论。

回答(2 个)

dpb
dpb 2015-6-28
编辑:dpb 2015-6-28
"Trouble reading number from file (row 1u, field 1u) ==>rssd9999^rssd9001^BHCK0081^BHCK0395^..."
>> help dlmread
dlmread Read ASCII delimited file.
RESULT = dlmread(FILENAME) reads numeric data from the ASCII
delimited file FILENAME. The delimiter is inferred from the formatting
of the file.
...
All data in the input file must be numeric. dlmread does not operate
on files containing nonnumeric data, even if the specified rows and
columns for the read contain numeric data only.
You can't read the file with dlmread per the doc above; it must be numeric data only. Use textscan
ADDENDUM
OK, w/ more info on the file that that's a header line, if you have recent release of Matlab, try readtable instead. It should figure out the number of elements/record automagically.
  3 个评论
Walter Roberson
Walter Roberson 2015-6-28
The column headers are stored in the file, right? dlmread() cannot handle text anywhere in the file.
dpb
dpb 2015-6-28
That IS nonumeric data in the file; reread the help...

请先登录,再进行评论。


Jan
Jan 2015-6-28
DataStr = fileread('bhcf0003.txt');
DataCell = regexp(DataStr, '\^', 'split');
Now you have a cell string: {'rssd9999', 'rssd9001', 'BHCK0081', ...}
  1 个评论
wesso Dadoyan
wesso Dadoyan 2015-6-28
I obtained 1x2561266 cell array. I have too many files like this where each row should correspond to a firm. It is very confusing to extract the data related to a specific firm from this cell array. All what I am wondering about is how to read in matlab the text file that I sent the way excel reads it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by