필터 지우기
필터 지우기

How to correctly read in a csv file using csvread?

조회 수: 197 (최근 30일)
Aidan Goy
Aidan Goy 2020년 11월 23일
댓글: Rik 2020년 12월 7일
I have a CSV file I need to read in and I need to use csvread to do this, I cant seem to figure out how to get it to read in correctly as when I read in it saves as a 407x1 array and does not include the various headings from my csv file which looks like this
The full CSV has 407 rows and 9 columns. I need read the csv file to a point where I am then able to work with each specific column in order to create graphs etc but I have been struggling for quite some time now to get this read in correctly. I also have the option to save as a text file and use fopen fclose fread etc if that would make my task easier?
Thanks
  댓글 수: 1
Rik
Rik 2020년 12월 7일
Regarding your flag: you received answers on both questions, so I don't think you should delete either question. Please don't post duplicates in the future.

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

답변 (1개)

Star Strider
Star Strider 2020년 11월 23일
Since you have R2020b, use readtable instead.
(Also, note that Update 2 has recently been released.)
  댓글 수: 2
Aidan Goy
Aidan Goy 2020년 11월 23일
Is it possible to do it without using readtable and instead using csvread?
Star Strider
Star Strider 2020년 11월 23일
I seriously doubt it, given the file contents displayed. In general, .csv files contain only numeric data, although csvread allows for a header line (and the ability to skip it). For your file, readtable appears tro be the only viable option.
Tables are realtively easy to work with, although if you are unfamiliar with them, they can require a bit of initial effort to understand. See for example Access Data in Tables, and other documentation in and linked to in the table documentation. If you only want to use the numeric data initially, that is certainly possible. Later, if you need the text data, it will be there for you to use.
I will help you work with the data in your table, if you need help. I certainly encourage you to use readtable. Be sure to use ,'VariableNamingRule','preserve' in the readtable call so the variable names (column headers) are imported without change. To then use those those variable names, put them in single quotes, so if ‘T’ is your table, to refer to ‘car name’:
Name = T.('car name');
and so for any of the others with similar variable names. To refer to the other variables, the normal conventions apply.

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

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by