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

조회 수: 2 (최근 30일)
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
Geoff Hayes
Geoff Hayes 2014년 6월 10일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by