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!