Reading csv or excel file with three headliners
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Benju Baniya
el 5 de Abr. de 2023
Comentada: Benju Baniya
el 5 de Abr. de 2023
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 comentarios
Respuesta aceptada
Walter Roberson
el 5 de Abr. de 2023
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!