Read Files from Directory
292 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Clement Wong
am 10 Aug. 2011
Bearbeitet: Walter Roberson
am 10 Jul. 2022
Hey,
I'd like to be able to give a program a directory, and then have it run a second program on all files in that directory. For example, say I have a function, myFun(filePath) that reads, processes, and displays data from the file specified by filePath. Now, I'd like to write another function, in pseudocode below:
funtion dirFun(dirPath)
f = files(dirPath);
for x = 1:length(files);
myFun(f[x]);
end
Something like this. I want a function, here "files" which will return all of the file names within the directory, so that I can run the program on all my files. Is there such a function in MATLAB?
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 11 Aug. 2011
The function is dir().
Files=dir('*.*');
for k=1:length(Files)
FileNames=Files(k).name
end
4 Kommentare
Walter Roberson
am 10 Jul. 2022
Bearbeitet: Walter Roberson
am 10 Jul. 2022
What leads you to expect that nearly 11 years ago, @Clement Wong happened to need to start from the third entry instead of the first?
I suspect that you are thinking that the first entry is "." and the second entry is ".." but if so then that is an incorrect assumption on every operating system that MATLAB has ever been supported on. If you want to filter out "." and ".." you should do so by name, not by assuming they are in a particular position.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!