Reading large CSV files with MATLAB

Reading very large CSV files in MATLAB can be extremely slow and may even cause MATLAB to freeze or crash.

A few weeks ago I was trying to read a CSV file of ~300MB, and it took forever to load although I have a fairly good laptop (i7-3537U, 8GB RAM, etc). In my search for faster ways to load, I found a script which I believe was written by Stanisław Adaszewski. Unfortunately, his website ALGOHolic seems to be down, and I haven’t been able to find other places to download his script. I have therefore decided to share his unaltered work. Usage:


quote = '"';
sep = ';';
escape = '\';
[numbers, text] = swallow_csv(filename, quote, sep, escape);

The attached archive contains compiled MEXW64 version. For other OS/architecture you need to:
mex swallow_csv.cpp

swallow_csv.zip

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Code examples
Live digital donation signature wall (source code included)

I was recently involved in an non-profit related event, where guests could participate in a lottery and win prices. To make the event more interesting, when someone either digitally or physically donated money, their name would appear/update on a large TV-screen. If they had already donated money, their name would …

Code examples
Reading XML files in matlab

Reading XML files in MATLAB has yet to become user friendly as it already is in other object-oriented programming languages. The most confusing thing is that objects appear to be empty or NULL when you access variables in MATLAB. So I decided to put up a simple code example that …