MATLAB Answers

0

Importing CSV files into MATLAB

Hans123 님이 질문을 제출함. 22 May 2019
최근 활동 Walter Roberson 님이 답변함. 22 May 2019
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?

  댓글 수: 0

로그인 to comment.

답변 수: 1

Walter Roberson 님의 답변 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.

  댓글 수: 0

로그인 to comment.



Translated by