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

1 回表示 (過去 30 日間)
Meshooo
Meshooo 2014 年 6 月 9 日
コメント済み: Meshooo 2014 年 6 月 12 日
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.
Meshooo
Meshooo 2014 年 6 月 12 日
Yes, it works very well. Thank you very much.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by