MATLAB Answers

Fastest Way of Opening and Reading .csv Files (Currently using xlsread)

137 ビュー (過去 30 日間)
Ibro Tutic
Ibro Tutic 2016 年 5 月 23 日
コメント済み: Walter Roberson 2020 年 8 月 25 日
I am currently trying to convert 100,000+ csv files (all the same size, with the same data structuring on the inside) to mat files, and I am running into the issue that it takes an extremely long time, and sometimes Excel stops responding. Are there any other functions that could cut down on the read time of these .csv files?
I read something about trying the COM server that runs Excel, but I am not sure how to implement it. Any thoughts?


Kirby Fears
Kirby Fears 2016 年 5 月 23 日
編集済み: Kirby Fears 2016 年 5 月 23 日
Thankfully, you don't need to interact with Excel to read csv files. You can use textscan to read csv files quickly.
I wrote a function called delimread that utilizes textscan with automatic parameters. It might be easier than learning how to parameterize textscan.

その他の回答 (3 件)

Jeremy Hughes
Jeremy Hughes 2017 年 8 月 23 日
Since you have multiple files, you may want to consider using datastore. (Since R2014b)
In many cases, you can just use the following pattern to read a large collection of files,
ds = datastore('folder/containing/your/files')
t = read(ds)
% do stuff to t.
Hope this helps,

TastyPastry 2016 年 5 月 23 日
There's a function csvread() which only works on numeric data.
The other way you can do it is to use textscan(). Both of those methods should be faster than xlsread() since xlsread() uses Excel, which is pretty slow.
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 25 日
csvread calls dlmread calls textscan.


Community Treasure Hunt

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

Start Hunting!

Translated by