フィルターのクリア

How to correctly read in a csv file using csvread?

203 ビュー (過去 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 Center および File ExchangeString Parsing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by