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.
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.
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.
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.
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 :)
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.
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
readtext seems faster
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.
I love it. It saves me so much time.
I have been trying to load this data for hours, and at last, thanks to this, I have now loaded it.
I thank you for providing this utility.
Very useful code. Solves some annoying text-file related problems in MATLAB. Thanks!
Very nice. Does exactly what I want. (again, good for small dataset)
A good tool that solves a long standing problem.
very good code. speed can be resolved with better machines :):) many thanks to the author.
Works well but it's kinda slow if you have a larger data file.
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.
Had some problems but its really OK.
Very helpfull for me to load the data I needed.
Thank you for adding this. I have advertised this as a "must have" part of any matlab setup to my collegues.
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.
Please pardon the interruption, but
thank you for writing and posting your
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')
Minor updates to enhance speed.