Reading data from csv files
Mostrar comentarios más antiguos
I have 37 csv files. I need to read data from first row of all the 37 files and merge these 37 rows into one mat file.
Then I will read all the 2nd rows and merge them into one mat file.
I will keep reading the data till the last row of each csv file.
Name of my csv files are:
Col01_all
Col02_all
.
.
.
Col37_all
I am not sure how to do this.
7 comentarios
Adam Danz
el 23 de Abr. de 2019
I suggest you read the entire files into matlab (in a loop) and then collate the rows as needed after the data are in your workspace.
Read the files in a loop, using sprintf to generate the filenames:
As Adam Danz wrote, it would be easiest if you simply import the whole files and the use indexing to select the rows that you need.
Ahmad Hasnain
el 23 de Abr. de 2019
dpb
el 23 de Abr. de 2019
"Read the files in a loop, using sprintf to generate the filenames:"
For that type of a set of file names, I'd use the dir solution with a wildcard as being simpler...
d=dir(fullfile(wkdir,'Col*all.csv')); % presuming there is a .csv extension
for i=1:numel(d)
import/process file fullfile(wkdir,d(i).name)) here
end
Ahmad Hasnain
el 24 de Abr. de 2019
KSSV
el 24 de Abr. de 2019
Are you sure that all A{i} are of same size?
Ahmad Hasnain
el 24 de Abr. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!