How to upload a file or image from any directory which is not included in the matlab path?

3 views (last 30 days)
Dear all,
I am building a GUI by which one push button will allow the user to select an image that will be displayed in the axes.
However, I can only upload an image if its directory included in the matlab path. So how to upload an image which is not included in the path without resetting the path?
Any idea is welcome.
Meshooo
  2 Comments
Geoff Hayes
Geoff Hayes on 10 Jun 2014
What code are you using to allow the user to select an image? If I use uigetfile, I can select any file in any directory at my workstation. Try the following:
[fileName,pathName] = uigetfile('*.jpg');
imageFileName = fullfile(pathName,fileName);
I = imread(imageFileName);
The above code allows the user to select any jpg from any directory, and both the file name and path to the file are returned. The imageFileName (for lack of a better name) is then built using the path and file name. (Step through this code and view the contents of each variable.)
If your code is only using the file name, then that may explain why only files in the MATLAB path can be opened ("uploaded to the GUI"). Try the above and see if it helps.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!