How do I access a certain directory?

How do I access a certain directory, so i can then retrieve certain images from that specified directory?

Answers (2)

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
help cd

3 Comments

Stephen23
Stephen23 on 9 Sep 2019
Edited: Stephen23 on 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.
Ah :) thanks for the tips.

Sign in to comment.

Categories

Products

Release

R2019a

Asked:

on 9 Sep 2019

Commented:

on 9 Sep 2019

Community Treasure Hunt

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

Start Hunting!