fileDoesNotExist error with compiled application

hello:
I've compiled my Matlab code into an independent executable file. Upon reaching the point in the code where it requires the user to select an image to process - see below for that command - I get an error.
> loadimg = imread(uigetfile({'*.jpg;*.bmp;*.tif;*.png;*.gif'}))
after this, the user selects a file, and the executable reports the following:
> error using imread (line 349)
> file "pic 1.bmp" does not exist
> error in parsing2 (line 5)
> MATLAB:imagesci:imread:fileDoesNotExist
after this, the application quits.

 채택된 답변

Walter Roberson
Walter Roberson 2016년 7월 25일

1 개 추천

The executable is not in the directory that you assume it is in. You need to use the two-output version of uigetfile and then use fullfile() to construct the fully-qualified filename and imread() that. And remember to try/catch in case there is a problem.

댓글 수: 3

Mike Bocchinfuso
Mike Bocchinfuso 2016년 7월 26일
편집: Mike Bocchinfuso 2016년 7월 26일
hi Walter:
Which directory should the executable be in? The goal is to have this deployed to a separate computer (I'm doing the coding/debugging on my own computer for now), where the files are saved in one of several subfolders, but the selection of which image to work on would be left to the operator. Are fullfile() and uigetfile() still relevant in that case?
The executable's initial directory is typically the directory it was expanded into, which you can access under the function name ctfroot() . In MS Windows, OS-X and Linux, whenever you start a graphical executable by way of icon, the initial directory is set according to operating system rules, sometimes rules stored with the icon properties; the initial directory is not set according to which directory the user is "in" because in a graphical windowed system the user is "in" multiple directories simultaneously.
The solution is to use fullfile() to ensure that the directory portion gets filled out completely. In MS Windows you might want to use getenv() to look at the HOMEDRIVE and HOMEPATH environment variables.
hi Walter:
Thanks for your assistance. Using fullfile() works and my application is functioning.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by