Importing multiple csv files as separate structures
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Supriya Balaji Ramachandran
el 8 de Jul. de 2019
Respondida: Dheeraj Singh
el 16 de Jul. de 2019
I have a folder with several subfolders, each subfolder has several csv files. How do I import each csv file as a structure and put all structures inside one large cell array
1 comentario
Stephen23
el 9 de Jul. de 2019
"How do I import each csv file as a structure and put all structures inside one large cell array "
Start by looking at the examples in the MATLAB documentation:
Respuestas (1)
Dheeraj Singh
el 16 de Jul. de 2019
Hi,
I understand that you want to traverse folder which has subfolders, having csv files. You want to read csv files as a structure.
The following code implements the above functionality.
%folder = path to the folder;
D=dir(fold)
%traverse from 3 to numel
for i=3:numel(D)
%subfolder
currD=D(i).folder;
%change directory
cd(currD);
fList=dir(D(i).name);
f=fList.folder;
for j=3:numel(fList)
pa=fullfile(fList(j).folder,fList(j).name);
%read filke as a table
content=readtable(pa);
%convert a table to a structure
content=table2struct(content)
end
%go back to the previous folder
cd(D(i).folder);
end
0 comentarios
Ver también
Categorías
Más información sobre File Operations 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!