How to select a folder using uigetdir and use folder location later?

After acccessing a particular folder using uigetdir, i want to use folder location later in my code.
In the code mentioned below, how i can get the folder location details in the DOTTED place.
Please help me with that.
Thanks!
directory_name = uigetdir;
File01 = dir(fullfile(directory_name,'*.png'));
---
srcFiles02 = dir('F:\Matlab\Images\Constants\*.png');
---
% Comparision
for i = 1 : image01
Name01 = strcat(..........,File01(i).name);
---

 Accepted Answer

Do NOT use strcat, you should always use fullfile to build filepaths, just like you did for dir. Like this:
aa = fullfile(directory_name, srcFiles(j).name);
and exactly the same for bb:
D = 'F:\Matlab\Images\Symbols_Constants';
srcFiles2 = dir(fullfile(D,'*.png'));
...
bb = fullfile(D,srcFiles2(j).name);
...

3 Comments

If subfolders are searched, like if he wants to use double star in the file pattern passed to dir(), then D is not a constant and he should use
fullFileName = fullfile(srcFiles2(j).folder, srcFiles2(j).name);
image2 = double(imread(fullFileName)); % Read in the second image
Also, in general using single letter variables instead of descriptive ones leads to an alphabet soup mess of a program that is cryptic and hard to follow. However it's good to see an attempt at adding comments was made.
Thank you for the help. I got my problem sloved, with your support.

Sign in to comment.

More Answers (0)

Categories

Find more on Display Image in Help Center and File Exchange

Asked:

on 18 Nov 2018

Edited:

on 13 Jan 2019

Community Treasure Hunt

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

Start Hunting!