Code covered by the BSD License  

Highlights from
csv2struct

4.2

4.2 | 6 ratings Rate this file 24 Downloads (last 30 days) File Size: 2.03 KB File ID: #26106

csv2struct

by Jaroslaw Tuszynski

 

14 Dec 2009

reads Excel's files stored in .csv or .xls file formats and stores results as a struct

| Watch this File

File Information
Description

CSV2STRUCT reads Excel's files stored in .xls or .csv file formats and stores results as a struct.

DESCRIPTION
The Excel file is assumed to have a single header row. The output struct will have a field for each column and the field name will be based on the column name read from the header.

Unlike csvread, csv2struct is able to read files with both text and number fields. Unlike xlsread, csv2struct is able to read .csv files with more than 65536 rows.

Utility was originally written for reading large .csv files.
 
See also:
  MATLAB's csvread and xlsread functions
  xml_read from my xml_io_tools which creates struct out of xml files

Acknowledgements
This submission has inspired the following:
Struct array conversion
MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
16 Mar 2010 Pete

Have only just started playing with this script, but so far it seems to be another truly excellent utility from Jaroslaw Tuszynski.

Does everything it says. Columns with text come out as cells. Columns with numbers come out as matrices. And all of them are stored in a structure such that you can reference them by the name of the column header.

This seems to me far superior to anything else I've found either here on FEX, or built in to Matlab (though I'm only running R2007a at the moment, so I can't comment on newer releases).

Will post an update if I come across any problems further down the line, but on present experience I highly recommend this script!

 

25 Mar 2010 Ged Ridgway

Really useful submission!

Works nicely on .xls, but doesn't seem to work on .csv for me... In particular, xlsread (which csv2struct relies on even for .csv) doesn't seem happy with .csv files at all; I'm not sure if this is a platform issue (xlsread under Windows can be more advanced than xlsread under Linux, which I'm currently using) or a version issue (I'm currently using R2006a). Any ideas? (It's easy enough to convert csv to xls, and then use it, but csv is more widely compatible than xls for other software...)

16 Aug 2010 Alfred  
12 Nov 2010 Michael Chan

It's really useful.
just a minor error.

line 78: name = char('A'-1+c);
instead of
    name = char('A'-1+i);

03 Jan 2011 Pete

@Ged: "***If your system does not have Excel for Windows installed, or MATLAB cannot access the COM server, xlsread operates in basic mode. In this mode, xlsread only reads XLS files.***"

Yeah this is unfortunate - would seem to mean that this script will only work on windows machines. Not the author's fault, but down-rated accordingly =/

15 Aug 2011 Shlomi

it didn't work well for me when I passed a csv file which size exceeded 2^16.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
csv Jaroslaw Tuszynski 15 Dec 2009 09:48:04
csvread Jaroslaw Tuszynski 15 Dec 2009 09:48:04
read csv Jaroslaw Tuszynski 15 Dec 2009 09:48:04
data import Jaroslaw Tuszynski 15 Dec 2009 09:48:04
xls Jaroslaw Tuszynski 15 Dec 2009 09:48:04
parse csv Jaroslaw Tuszynski 15 Dec 2009 09:48:04
csv Ho-Cheol Lee 08 May 2011 20:08:21

Contact us at files@mathworks.com