Reading CSV files in Matlab.

Comma Separated Values data can be imported in Matlab using the "Import Data" wizard or the importdata function for reading ASCII data with column separator.

Example


% Based on code auto-generated by MATLAB 
% File to read
FILENAME = 'test.csv';

% Define delimiter and number of header lines
DELIMITER = ','; % use ';' for CSV with semicolon separator
HEADERLINES = 15;

% Import the file
newData = importdata(FILENAME, DELIMITER, HEADERLINES);

% Create new variables in the base workspace from those fields.
vars = fieldnames(newData);
for i = 1:length(vars)
    assignin('base', vars{i}, newData1.(vars{i}));
end

spacer