matlabmatlab-deploymentmcc

File addressing of code for MATLAB compiler


In my codes, there are some functions like imshow or fopen files that need addressing. When I use my program in MATLAB I use pwd like imshow([pwd '/image.jpg']) for addressing and the program run and work correctly, but when I compiled my program after installing it (redistribution) when I open shortcut in desktop, an error message appear with the title that my program can't find image.jpg . When I check the address of searching, it is like :

C:/User/Desktop/image.jpg

I read this page but I don't know how to use this addressing.

http://www.mathworks.com/matlabcentral/answers/59148-for-stand-alone-exe-how-do-i-include-a-folder-of-files-and-know-how-to-access-them

Beside It I don't know where I should add these files ( images and texts ) in MATLAB compiler options. In file required for your application to run or file installed with your application.

Thanks.


Solution

  • That is because your image is not located in your current path (i.e. the desktop in this case).

    If you want to use images, you should include the image in deploytool's "shared Resources and helper files" and in your script/function reference the image as specified in the link, using:

    if isdeployed
        imagepath = [ctfroot filesep 'image.jpg'];
    else
        imagepath = [pwd filesep 'image.jpg'];
    end
    % Now use imagepath as if it was [pwd filesep 'image.jpg']
    [A] = imread(imagepath);
    

    Other option is including the file (image.jpg) in the same path as your final executable, since you are calling the image from pwd.