Importing CSV files into MATLAB

20 views (last 30 days)
I am trying to import multiple CSV data files into MATLAB without manually doing so (by hard coding), I want the data as a double and not in table - so the command
T = readtable('myfile.csv');
or
T = readtable('myfile.csv', 'HeaderLines',3); % skips the first three rows of data
is not the best choice to use. How can I import the data from these comma seperate value files like how dlmread works with Excel files?
Is csvread a good approach? Becuase when I read the litreature (https://www.mathworks.com/help/matlab/ref/csvread.html) it says it is Not Recommended.
I was working with Octave for a while and the dlmread function works well with it, why doesn't MATLAB have that functionality?

Accepted Answer

Walter Roberson
Walter Roberson on 22 May 2019
In R2019a there is now readmatrix() for reading numeric values (not mixed data type).
Before that, you can use readtable() and table2array(), provided that you do not have mixed data types.
dlmread() is restricted to numeric values, with the exception that you can tell it how many leading rows and columns to skip, and those skipped rows or columns can contain text. Be careful when you give those parameters, as it is the number to skip, not the offset of the first one you want to read -- so for skipping 3 rows and no columns that would be 3, 0. It is not a starting row -- you would not specify 4, 1 to tell it to start reading from row 4 column 1 for example.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!