Error while reading table
显示 更早的评论
Hello,
I am trying to read the data of the attached excel file. However, when I use readtable, only values upto row 2881 are loaded in a table in MATLAB. Can you tell me how to resolve this issue?
Thanks!
2 个评论
I can't open that file in Excel to see how many rows it has, but readcell reads 2886 rows, the first 5 or 6 of which look like the header.
C = readcell('n_fot2017-01-12.xls')
Evidently, readtable is interpreting 5 header rows and putting the remaining rows into a table with 2886-5 = 2881 rows.
T = readtable('n_fot2017-01-12.xls')
If you want to tell readtable that there are 6 header rows, you can do that, and then you'll get a table with 2886-6 = 2880 rows.
T = readtable('n_fot2017-01-12.xls','NumHeaderLines',6)
采纳的回答
更多回答(1 个)
So far, the orignal file has some VB issues. Therefore, none of the suggest solutions can read the whole data even if the imported data size is correct. The solution is to save the file *.xls as *.csv (UTF-8) and then import the data.
D1 = readtable('n_fot2017-01-12.csv', 'Range', 'A2:K8761');
size(D1)
D1(end,:) % Whole data is read correctly. It does not stop at row 2886
% Compare
D2 = readtable('n_fot2017-01-12.xls', 'Range', 'A2:K8761');
size(D2) % Size is correct
D2(end,:) % BUT Not correctly read
C = readcell('n_fot2017-01-12.xls', 'Range', 'A2:K8761');
size(C) % Size is correct
C(end,1) % BUT Not correctly read
1 个评论
An alternative way to import the whole data is as Chris mentioned (because of the hidden sheet = Blad1), by specifying the sheet name, e.g.:
D1 = readtable('n_fot2017-01-12.xls', 'Sheet', 'Förb + prod i Sverige');
size(D1)
D1(end,:)
% OR Note dates are not read in the right format
D2 = readmatrix('n_fot2017-01-12.xls', 'Range', 'A2:K8761', 'Sheet', 2);
size(D2)
D2(end,:)
类别
在 帮助中心 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!