How can I convert csv files to matlab whilst also looping through folders?

1 visualización (últimos 30 días)
JJH
JJH el 15 de Nov. de 2018
Respondida: Jan Studnicka el 15 de Nov. de 2018
I have been trying to write a code that loops through a set of folders that all contain a set of files. The files in each folder have the same name, it is only the name of the folder that varies. So far I have
SpectrumFileInfo = dir('Spectrum Data*');
NSpec = numel(SpectrumFileInfo);
for i = 1:NSpec
SFI(i) = SpectrumFileInfo(i);
end
for k = 1:length(SFI)
FolderName = SpectrumFileInfo(k).name;
Direc = dir([FolderName '\I*']);
NumFiles = numel(Direc);
for kk = 1:NumFiles
[num,text,raw] = csvread(Direc(k).name);
[dummy, myName] = fileparts(Direc(k).name);
save(myName)
end
end
but this says there is an error in the csvread command (too many output arguments). I took this part from a code I found for xlsread and didn't really understand but what I want to do is convert each file in each folder to a mat file with the same name. How can I edit this section of the code to do this? My files are a bit too big to include here.

Respuestas (1)

Jan Studnicka
Jan Studnicka el 15 de Nov. de 2018
Hi,
I would try using datastore:
Hope it helps.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by