Ali Bodaghi
Ali Bodaghi

Reputation: 71

Change MATLAB folder path

I have a general path

C:\Users\Dr Syed Abdul Rahman\Desktop\innovation final.

However I don't know how can I change my MATLAB path to

C:\Users\Dr Syed Abdul Rahman\Desktop\innovation final\Fingerprint 

or

C:\Users\Dr Syed Abdul Rahman\Desktop\innovation final\Image.

I know the cd command in MATLAB, but suppose that if this file is portable to other PC? Could anyone guide me how can I change my directory in somehow that does not need the full address? Because I have classified my image, folders, files and code...

Upvotes: 0

Views: 1069

Answers (2)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

Have a look at uigetfile -- it opens a normal dialog box that lets the user select a file in any location.

Alternatively, if you are running a script and you know that the image(s) is (are) always located in the same spot relative to that script, you can use fileparts in combination with mfilename('fullpath') to get the full path to the running script, and then append the rest via string concatenation. Something like this:

scriptPath    = fileparts(mfilename('fullpath'));
imageLocation = [scriptPath filesep 'Image' filesep];

img = imread([imageLocation 'your_image.jpg']);

Upvotes: 0

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137398

I'm fairly confident you can use relative paths with cd:

cd Fingerprint

And change back with

cd ..

Although I must ask - are you sure you want to be changing directories? Or should you instead be using relative paths when opening files? (eg. Image/foo.jpg)

Upvotes: 3

Related Questions