Home > general > io_fun > xls2struct.m

xls2struct

PURPOSE ^

XLS2STRUCT Reads 1D data + fieldnames from xls/csv file into matlab struct (BETA).

SYNOPSIS ^

function varargout = xls2struct(fname,varargin)

DESCRIPTION ^

XLS2STRUCT    Reads 1D data + fieldnames from xls/csv file into matlab struct (BETA).

 DATA = xls2struct(fname)
 DATA = xls2struct(fname,work_sheet_name)
 DATA = xls2struct(fname,work_sheet_name,<keyword,value>)
 DATA = xls2struct(fname,<keyword,value>)

 [DATA,units         ] = xls2struct(fname,work_sheet_name,<keyword,value>)
 [DATA,units,metainfo] = xls2struct(fname,work_sheet_name,<keyword,value>)

 where the xls has the following structure:
 * fieldnames (column names) at the first line.
 * units at the second line.
 * every line starting with one of '*%#' is interpreted 
   as a comment line.
 * all text fields with text 'NaN' are interpreted as numeric NaNs

 Example:

 +---------------+---------------+---------------+-----------------+-+-----------------+
 |# textline 1   |               |               |                 | |                 |
 |# textline 2   |               |               |                 | |                 |
 |# textline 3   |               |               |                 | |                 |
 | columnname_01 | columnname_02 | columnname_03 | columnname_04   | |                 |  
 | units         | units         | units         | units           | |                 |
 | number/string | number/string | number/string | number/string   |:| number/string   |
 | number/string | number/string | number/string | number/string   |:| number/string   |
 | number/string | number/string | number/string | number/string   |:| number/string   |
 | ...           | ...           | ...           | ...             | | ...             |
 | number/string | number/string | number/string | number/string   |:| number/string   |
 +---------------+---------------+---------------+-----------------+-+-----------------+

 and <keyword,value> pairs are:

 * addunits    true by default, adds units to DATA struct when 
               there is only 1 output argument (this option should be 
               removed, as there can be columns in the xls labelled units)
               e.g. ..\..\applications\knmi\knmi_etmgeg.csv
 * error       throw error when instead of returning empty matrices.
 * units       true by default, specifies whether the units at 
               the second line are present.
 * fillstr     str that represents dummy string values that should be replaced with number fillnum
               (Default {}, suggestion: {'NA'})
 * fillnum     number that replaces fillstr 
               (Default NaN)
 * commentchar characters that define the start of a comment (header) line (default '%*#')  
 * last2d      inserts all data to the right of the last column name 
               into the last variable such that the last variable is a (ragged) 2D array
               (default false as otherwise crap cratch notes might end up in your data)

 Notes:
 
 + The last columns extending the fieldnames are added to the 
   last fieldname as array. Make sure there's no extra columnwith spaces !
   In case of error just delete the (seemingly) empty rows and columns.
 + Elements where excel displays #DIV/0! or where you entered the 
   string 'nan' are considered as numerical nans.
 + Do not use 'units' as a fieldname, since the units (2nd line)
   are already loaded to a field called 'units', with a subield
   for every main field.

 See also: STRUCT2XLS, XLSDATE2DATENUM, XLSREAD, XLSWRITE (2006b+, otherwise mathsworks downloadcentral)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
Generated on Mon 29-Nov-2010 15:42:51 by m2html © 2005