Read a CSV file

조회 수: 2 (최근 30일)
Govind Sankar Madhavan Pillai Ramachandran Nair
댓글: Guillaume 2019년 1월 14일
I have a CSV file that is auto generated from my LabVIEW program. Even though it is a CSV file the LabVIEW program uses semicolon as the delimeter. Now I want to import this CSV file into MATLAB. There are total of 27 rows and 32 columns. The first row consists completely of string values that are the headings, i.e temp1, temp2, temp3 etc upto temp 32. Then from row 2 to row 27 are numeric values. How can I import both the string values and numeric values in the format 27x32. It can be cell or struct. But how to achieve this.
  댓글 수: 2
Rik
Rik 2019년 1월 14일
I would read the file in two steps: reading the headers separately from the rest of the data.
Govind Sankar Madhavan Pillai Ramachandran Nair
how can I do that

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2019년 1월 14일
Probably the simplest is to use readtable to import the data as a table. readtable should be smart enough to recognise that the first row is a header used to name the columns and use that to name the variables of the table. readtable will also have no issue recognising that the separator is a semicolon, so:
t = readtable(yourfile)
is probably all that is needed. If not, the options of readtable can be used to fix the problem, or if really pushed, detectImportOptions.
  댓글 수: 3
Jeremy Hughes
Jeremy Hughes 2019년 1월 14일
The function detectImportOptions is available in R2016b. In R2015b and earlier, readtable always assumed ',' was the delimiter, and that there were no header lines. You'll have to set these appropriate to the content of the file. Without seeing a file, that's as close to an answer as I can give.
Guillaume
Guillaume 2019년 1월 14일
Possibly, try:
B = readtable(filename, 'Delimiter', ';')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 LabVIEW에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by