How to apply function to certain files in directory
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
fernando aguirre
el 16 de Jul. de 2018
Editada: Moulvi Faizan Ahmed
el 11 de Dic. de 2019
I have a directory full of different files. The function I have will fopen and fread the content and process it to create other files. My function takes in parameter (parameter being the title of the file), but I would like to make the function run through the directory and read only the .raw files in that folder. Any help?
0 comentarios
Respuesta aceptada
Pawel Jastrzebski
el 16 de Jul. de 2018
Just get the function to work on the selected files in the folder to begin with:
i.e.
fileNames = dir('*.raw'); % structure
fileNames = {fileNames.name}; % actual names extracted to cell array
1 comentario
Moulvi Faizan Ahmed
el 11 de Dic. de 2019
But for the above method to be applicable the folder has to be in the current directory.
I need help on how to do the above requested task when the folder is not in the current directory and i dont want to change the directory.
Más respuestas (1)
Stephen23
el 11 de Dic. de 2019
Editada: Stephen23
el 11 de Dic. de 2019
D = 'relative/absolute path to the directory where the files are saved';
S = dir(fullfile(D,'*.raw'));
for k = 1:numel(S)
F = fullfile(D,S(k).name);
yourFunction(F)
end
1 comentario
Moulvi Faizan Ahmed
el 11 de Dic. de 2019
Editada: Moulvi Faizan Ahmed
el 11 de Dic. de 2019
Worked like charm, thank you
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!