How can I import a CSV file into MATLAB?. A row in the file i am working with looks like:
SUNW,2-Jan-98,1998,5,40.125,41.5
There are 36 columns and 10107 rows. The first row contains the column headers. It seems that MATLAB doesn't support importing such kind of CSV files. Using the following textscanfunction reads the whole data into one cell array.
data = textscan(fid, '%s %s %d %d %f %f', ...
'HeaderLines',1, 'Delimiter',',', 'CollectOutput',1);
Is there a way I could read the data into different variable for each column?
Example 6 in the
textscandocumentation seems to cover the use case that you're interested in:While it doesn't explicitly assign each column to a separate variable, you can easily do something like
col1 = C{1};.