xxlibReadCsv - reads comma separated value (csv) file Syntax: [values, names] = xxlibReadCsv(fileName, sepChar) Inputs: filename = full path of csv file (required) sepChar = separating character of csv file (optional) e.g ';' OR ',' (default) Outputs: names = list of strings on the first row values = column under each name See also: xxlibReadCsvHeader Author: Controllab Products B.V. email: info@controllab.nl Website: http://www.controllab.nl September 2013
0001 function [values, names] = xxlibReadCsv(varargin) 0002 % xxlibReadCsv - reads comma separated value (csv) file 0003 % 0004 % Syntax: 0005 % [values, names] = xxlibReadCsv(fileName, sepChar) 0006 % 0007 % Inputs: 0008 % filename = full path of csv file (required) 0009 % sepChar = separating character of csv file (optional) e.g ';' OR ',' (default) 0010 % 0011 % Outputs: 0012 % names = list of strings on the first row 0013 % values = column under each name 0014 % 0015 % See also: xxlibReadCsvHeader 0016 % 0017 % Author: Controllab Products B.V. 0018 % email: info@controllab.nl 0019 % Website: http://www.controllab.nl 0020 % September 2013 0021 0022 %------------- BEGIN CODE -------------- 0023 %check input arguments 0024 if length(varargin)==0 0025 error('Not enough input arguments.'); 0026 elseif length(varargin)>2 0027 error('Too many input arguments.'); 0028 end 0029 0030 if ~ischar(varargin{1}) 0031 error('Input argument 1 should be a file name.'); 0032 else 0033 filename = varargin{1}; 0034 end 0035 0036 if length(varargin)==2 0037 sepChar = varargin{2}; 0038 else 0039 sepChar = ','; 0040 end 0041 0042 names = xxlibReadCsvHeader(filename, sepChar); 0043 values = dlmread(filename, sepChar, 1, 0); 0044 end 0045 %------------- END OF CODE --------------