Matlab xlsread切断文件后行1048576 [英] Matlab xlsread cutting off file after row 1048576

查看:295
本文介绍了Matlab xlsread切断文件后行1048576的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何其他方法导入Excel格式化的.csv到Matlab而不是xlsread(file.csv);

Is there any other way of importing an Excel formatted .csv into Matlab other than xlsread(file.csv);

文件我包含2830082行,

The file I have contains 2830082 lines, and xlsread seems to have a limit of 1048576 lines when reading it - the rest gets cut off.

这个文件看起来像:

Time, Value
12:07:29, -1.13
12:07:29, -7.54
...

因此,使用csvread(..)不会工作,因为日期格式。

So using csvread(..) isn't going to work because of the date format.

推荐答案

我发现将BIG csv文件读入Matlab的最快方法是将它们内存映射并将内容解析为单个字符串。尝试使用此示例代码:

I've found the fastest way to read BIG csv files into Matlab is to memory-map them and parse the contents as a single string. Try playing with this example code:

fname = 'file.csv';
fstats = dir(fname);
% Map the file as one long character string
m = memmapfile(fname, 'Format', {'uint8' [ 1 fstats.bytes] 'asUint8'});
textdata = char(m.Data(1).asUint8);

% Find the end of each line, and use the line ends to form an index array
row = strfind(textdata, sprintf('\r\n'));
row = [[1; row(1:end-1)'+2] row' - 1];
% Fix-up if there is no \r\n at the end of the last line
if (row(end) < fstats.bytes - 2)
    row = [row; [row(end) + 2, fstats.bytes]];
end
numrows = size(row, 1);
% Create output variables
Time = zeros(numrows, 1);
Value = zeros(numrows, 1);

% Parse each line of the data (I'm ignoring the first line for simplicity)
for RowNum = 2:numrows
    data = textscan(textdata(row(RowNum,1):row(RowNum,2)), '%[^,]%f', 'delimiter', ',');
    Time(RowNum) = datenum(data{:});
    Value(RowNum) = data{2};
end

% Remove the file mapping
clear('m');

这篇关于Matlab xlsread切断文件后行1048576的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆