Reading csv files starting from a different row
19 ビュー (過去 30 日間)
古いコメントを表示
I have this csv file which I would like to import into Matlab. The "readtable" function allows me to import the csv into matlab easily into a table format. It automatically makes the first row the column names and assigns the cell A1 "Var1" since it is empty.
However, what I would like it to do is to read assign the column names according to the 3rd row since that contains the proper headers.
Is it always possible to locate the row containing " time(s) " and make that particular the header when using the readtable function?
Or is there an alternative method available that is accomplish the tasks mentioned above?
edit: attached the csv file
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/529554/image.png)
2 件のコメント
KALYAN ACHARJYA
2021 年 2 月 24 日
編集済み: KALYAN ACHARJYA
2021 年 2 月 24 日
Please attach the data file
See detectImportOptions
採用された回答
Mohammad Sami
2021 年 2 月 24 日
編集済み: Mohammad Sami
2021 年 2 月 24 日
You can use the import options to change the behaviour of the readtable function.
a = delimitedTextImportOptions('VariableNamesLine',3,'DataLines',5);
% or
% a = detectImportOptions('myfile.csv','VariableNamesLine',3,'Range',5);
b = readtable('myfile.csv',a);
% use the following if excel file
% a = detectImportOptions('testfile.xlsx','VariableNamesRange','A3','DataRange','A5');
6 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!