【问题标题】:Fast csv import快速 csv 导入
【发布时间】:2019-05-22 20:22:04
【问题描述】:

我希望将大量 csv 文件导入 MATLAB。我可以毫无困难地做到这一点,除非它需要很多时间 - 每个文件大约 3 秒,使用以下代码。有没有办法更快地做到这一点?这里A 是一个15 行250 列的矩阵。有 150 个文件。

tic

file_name = [];
for w = scenario_size:-1:1
    file_name = sprintf('monthly_population_%d.csv',w) ; % read file name f
    A = xlsread(file_name);                
    pop(:,:,w) = A' ; 
end
clear A
toc

【问题讨论】:

  • 如果您的.csv 文件格式一致,我认为阅读它们的最快方法是使用tesxscanfscanf

标签: matlab csv import-from-csv file-import


【解决方案1】:

您可能通过使用 readmatrix 而不是 xlsread 提高了性能。例如:

A = readmatrix(file_name);

或者,如果您使用的是没有 readmatrix 的 Matlab 版本,请尝试 readtable:

A = table2array(readtable(file_name));

【讨论】:

  • readmatrix 是在 R2019a 中引入的。对于旧版本,请使用csvread
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
  • 2016-04-12
  • 1970-01-01
  • 2016-02-27
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
相关资源
最近更新 更多