How do I access a certain directory?
Ältere Kommentare anzeigen
How do I access a certain directory, so i can then retrieve certain images from that specified directory?
Antworten (2)
Jan
am 9 Sep. 2019
You can define the path of a file to access it:
Folder = 'C:\Temp\';
FileList = dir(fullfile(Folder, '*.jpg'));
for iFile = 1:numel(FileList)
File = fullfile(FileList(iFile).folder, FileList(iFile).name);
% Do what you want with this file, e.g.:
Img = imread(File)
end
1 Kommentar
madhan ravi
am 9 Sep. 2019
+1
madhan ravi
am 9 Sep. 2019
help cd
3 Kommentare
cd is slow (searches for MATLAB files), changes function scope, and makes debugging harder.
Much better: access data files using fullfile and absolute/relative filenames.
Jan
am 9 Sep. 2019
It is unsafe to change to a specific directory only to access the included files. Using absolute path names is better, because this is not confused by GUI or TIMER callbacks, which call cd again unexpectedly.
madhan ravi
am 9 Sep. 2019
Ah :) thanks for the tips.
Kategorien
Mehr zu File Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!