Code covered by the BSD License  

Highlights from
struct2csv

Be the first to rate this file! 63 Downloads (last 30 days) File Size: 1.87 KB File ID: #34889
image thumbnail

struct2csv

by James Slegers

 

02 Feb 2012 (Updated 18 Jun 2013)

Output a structure to a .csv file, with column headers

| Watch this File

File Information
Description

STRUCT2CSV(s,fn)

Output a structure of matrices and cell arrays to a comma delimited file with field names as column headers. A simple method for exporting data structures.

      s : any structure composed of one or more matrices and/or cell arrays
     fn : file name

Written by James Slegers, james.slegers_at_gmail.com

Covered by the BSD License

Required Products MATLAB
MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
csv(2), data export, header, struct, struct2csv(2)
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
24 Jun 2013 Kate

Nevermind the previous comment, simple path issue.

24 Jun 2013 Kate

Any clue why I would get this type of error message?

>> struct2csv(sitetable, 'info.csv')
Undefined function 'struct2csv' for input arguments of type 'struct'.

18 Apr 2013 Sebastian

Hi,

thanks a lot for this file!

But I found a little bug when a column is a "n x 1 char".

I fixed it with "an elseif":
c = getfield(s,headers{jj});
d = size(c);
if isnumeric(c)
str = [num2str(c(ii,kk)),','];
elseif d(2)==1
str = ['"',c(ii),'",'];
else
str = ['"',c{ii,kk},'",'];
end

Updates
18 Jun 2013

Rewrote significant portions of code, in response to noted bugs. Hopefully, the noted bugs have been remedied.

Contact us