MATLAB Answers

James
0

How do I access a certain directory?

Asked by James
on 9 Sep 2019
Latest activity Commented on by madhan ravi
on 9 Sep 2019
How do I access a certain directory, so i can then retrieve certain images from that specified directory?

  0 Comments

Sign in to comment.

Products


Release

R2019a

2 Answers

Answer by Jan
on 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 Comment

Sign in to comment.


Answer by madhan ravi
on 9 Sep 2019

help cd

  3 Comments

Jan
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.