Log In | Users | Register
Edit | Attach | New | Raw | Diff | Print | | Tools
You are here: Data » DocFormats » FormatCSV » CSVMatlab

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
This site is managed by the Center for Climate Systems Modeling (C2SM).
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems? Send feedback!