View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.9 | 23 ratings Rate this file 13 Downloads (last 30 days) File Size: 3.82 KB File ID: #1965 Version: 1.1




16 Jul 2002 (Updated )

Loads character seperated data with variable length lines and mixed types.

| Watch this File

File Information

Load any text-based data into MATLAB.

Loads data into cell array. Data can have variable length lines or be mixtures of numeric and string types.

[a,b,c]=loadcell(fname,[',' char(9)],'"','single-empty2num')

Will load tab or comma seperated values into a. Seperators lying between inverted comma pairs will be ignored. Repeated seperators will not be treated as one. All empty fields will be treated as numeric zeros rather than empty strings. b and c give further info. See help.

Other files:

celltonumeric.m will take a columnar cell array and map it to an entirely numeric array with numeric pointers into string arrays. Useful for actually doing stuff with the data you loaded!

datato1ofm.m will remap categorical data (e.g. that produced by celltonumeric) and represent it entirely as 1ofM binary data. It keeps track of what came from where so can be used form multinomial analysis too. Ideal for any count-based probabilistic analysis.


This file inspired Readtext.

MATLAB release MATLAB 6.0 (R12)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (26)
06 Aug 2012 Sumantra Sarkar

22 Jul 2011 Pierre Bushel

Wonderful function. Saves me a lot of time. One problem is that when I load data, the last row of the variable has blanks or some other weird character.

27 Mar 2010 Mark Cejas

Thanks a ton for this elegant solution. I am having trouble getting it to work...I keep getting the following error:

>> [lc,dflag,numdata]=loadcell('general categories',[',' char(9)],'"','single-empty2num')
??? Undefined function or variable "dflag".

Error in ==> loadcell at 200

any help for this newbie would be greatly appreciated :)

Comment only
13 Jan 2010 Amos Storkey

I have updated this and I think that it now competes in speed with readtext on the files I tried, and it has a few nuances that are useful.

I have also added celltonumeric and datato1ofm to file exchange. Just getting the data into a cell array is helpful, as the biggest problem with matlab is getting the data in. However, getting the data into a cell array does not make it very useful. Hence these two files turn this data into more useful numeric formats. They are short and sweet.

03 Mar 2009 m4lte k

02 Dec 2008 Amos Storkey

I have not updated this recently, and I would now agree that readtext does the most important things loadcell does, but is significantly faster. Hence I would recommend new arrivals at this page to try readtext first (see the Acknowledgements
This submission has inspired the following: readtext link above). Amos

Comment only
21 Jul 2008 Thierry Dalon

readtext seems faster

Comment only
01 Nov 2007 Philip Perea

Just learning MatLab (but an experienced programmer) and this program seems to do exactly what I need. Fantastic bit of code Amos. Thanks for sharing it.

06 Oct 2006 Pierre Bushel

I love it. It saves me so much time.

24 Feb 2006 Nacho T.

Super dooper

01 Nov 2005 Mike Good

I have been trying to load this data for hours, and at last, thanks to this, I have now loaded it.

27 Jul 2005 Kent Conover

I thank you for providing this utility.

04 May 2005 Amit Reches

Very useful code. Solves some annoying text-file related problems in MATLAB. Thanks!

03 Oct 2004 Ali Asghari

Very nice. Does exactly what I want. (again, good for small dataset)

28 May 2004 a hartmann

A good tool that solves a long standing problem.

04 May 2004 m hawarey

very good code. speed can be resolved with better machines :):) many thanks to the author.

03 Feb 2004 D. Wagener

Works well but it's kinda slow if you have a larger data file.

20 Jan 2004 M Srinivasan

Powerful and elegant! Very helpful in parsing lines with variable number of fields. I only wish there were a way to speed it up significantly - as fast as, say, Excel, when it opens up similar files.

03 Aug 2003 J Johnson

Pretty powerful.

02 Aug 2003 Mr Andersson

Had some problems but its really OK.

01 Aug 2003 Y Romay

Very helpfull for me to load the data I needed.

22 Jul 2003 John Adams


12 May 2003 J G

18 Apr 2003 James Conway

Thank you for adding this. I have advertised this as a "must have" part of any matlab setup to my collegues.

01 Apr 2003 Mike Douglas

The function matlab is missing! I found it so annoying that there is no easy way of just getting data like this (variable length, or mixed type) into matlab in the first place. But now there is... Thanks.

05 Sep 2002 Colin Campbell

Dear Amos:

Please pardon the interruption, but
thank you for writing and posting your
comprehensive "loadcell.m".

It saved me lots of grief massaging
the data I was working with -
basically .csv that Matlab's csvread
choked on because of mixed data types
and missing data. Thanks again!!!

I will be sure to mention your function
in MATLAB courses I give at Waterloo.


P.S. I used:

[lc, dflag, dattype] = loadcell
('test.csv', ',', '', 'single')



13 Jan 2010 1.1

Minor updates to enhance speed.

Contact us