No BSD License
4.71429
by Michael Robbins
13 Mar 2003 (Updated 18 Mar 2003)
CSVREAD for files with varying number of cols.
| Watch this File
If you have a file that has more commas in some lines than others, this is for you.
It's very simple, but it may help some of you.
Adding this code to the end of the function makes a variable for each column. The name is taken from the first (header) row
data = MM; clear MM; for i=1:size(data,2) cmd = ['MM.' data{1,i} ' = data(2:end,' num2str(i) ');']; eval(cmd); end
This function is indeed really great, and robust.
I added 1 line to hugely boost performance by preallocating the output array "MM". To do this, just add this line right before the "for" loop:
MM=cell(length(M),max(cellfun(@length,regexp(M,','))));
Excellent reader, but consume too much memory for large files
Simple and effective
Great! This function should be include by defalut in matlab. It works perfectly.
Indeed, it can help you! Perhaps you must add a few lines so it fits your needs, but it will work fine.
Contact us