Reading csv or excel file with three headliners
4 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a csv file (which is a eddy pro output) attached with 3 headliners. I want to import the data with headliners and have treid using this code to import the fle but it doesn't work. I can skip the first headliner.
filepath= 'G:\Shared drives\Project_Crockett\QAQC_plots\EC_Benju\';
filename = "smartflux.csv";
opts = detectImportOptions(filename,'NumHeaderLines',3); % number of header lines which are to be ignored
opts.VariableNamesLine = 2; % row number which has variable names
opts.DataLine = 4; % row number from which the actual data starts
opts.VariableUnitsLine = 3; % row number which has units specified
tbl = readtable('TestFile.csv',opts)
I get this error "Error using detectImportOptions (line 432)
Unable to find or open 'smartflux.csv'. Check the path and filename or file permissions."
Please help me solve this issue. Thank you.
0 件のコメント
採用された回答
Walter Roberson
2023 年 4 月 5 日
filename = "smartflux.csv";
That is a basic filename without any directory information.
filepath= 'G:\Shared drives\Project_Crockett\QAQC_plots\EC_Benju\';
Tnat assigns a value to a variable. filepath is not any kind of reserved name in MATLAB, so it does not have any other result: a variable is assigned, nothing else happens.
opts = detectImportOptions(filename,'NumHeaderLines',3); % number of header lines which are to be ignored
You pass the basic filename to detectImportOptions . detectImportOptions is going to search for the file along the MATLAB path but in this case is not going to find it.
What you should be doing is
filepath= 'G:\Shared drives\Project_Crockett\QAQC_plots\EC_Benju\';
filename = fullfile(filepath, "smartflux.csv");
opts = detectImportOptions(filename,'NumHeaderLines',3); % number of header lines which are to be ignored
opts.VariableNamesLine = 2; % row number which has variable names
opts.DataLine = 4; % row number from which the actual data starts
opts.VariableUnitsLine = 3; % row number which has units specified
tbl = readtable(filename, opts); %NOTICE CHANGE HERE TOO
その他の回答 (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!