Reading csv or excel file with three headliners
3 次查看(过去 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!