1

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.

Eghbal
  • 3,892
  • 13
  • 51
  • 112

1 Answers1

3

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.

Daniel Pereira
  • 391
  • 3
  • 6
  • Thank you for answer. I'm using R2014a. There are to options for adding : file required for your application to run or file installed with your application. – Eghbal Aug 01 '14 at 12:29
  • new searching path : `C:\Users\User\AppDAta\Local\Temp\User\mcrCache8.3\my_Program_name0\image.jpg` . Error : this file does not exist. – Eghbal Aug 01 '14 at 12:59
  • When I added files to `file required for your application to run` now the files are in `C:\Users\User\AppDAta\Local\Temp\User\mcrCache8.3\my_Program_name0\my_Program_name` but error is referring to `C:\Users\User\AppDAta\Local\Temp\User\mcrCache8.3\my_Program_name0\` – Eghbal Aug 01 '14 at 13:09
  • Another question @Dani . Some of my files are in folder besides my codes. How can I have same structure after compiling my program? – Eghbal Aug 01 '14 at 13:16
  • What you can do, and what I am actually doing because I think is easier and more transparent, is recreating your dirs and files in the final folder of the app. You can distribute your app within a ZIP, RAR, EXE Installer or whatever, so the final user will have the Matlab EXE and the rest of the files with the same "file structure" than you had when running from matlab. You must use relative paths or pwd. This will make easier to understand why is your app failing, required files and folders and it'll simplify the compilation process, since you don't need to add the files to the deployed app. – Daniel Pereira Aug 04 '14 at 17:13
  • For example, I just built an application that needs 5 files, which are located into two folders. When distributing my app, I compile the Matlab functions (with no additional files) and then make a zip with the Compiled "myApp.exe" and the two folders containing the 5 necessary files. Then, the final user extracts the zip, and since the files are located in their corresponding folders, the exe is able to find them in the correct path ([pwd filesep 'folder1' filesep 'file1.txt'], [pwd filesep 'folder2' filesep 'file5.txt']). – Daniel Pereira Aug 04 '14 at 17:18
  • Thank you for your answer but it is true when we create `exe` file not installer. What do you think? – Eghbal Aug 04 '14 at 17:20
  • Excuse me, I'm afraid I didn't understand your last question. – Daniel Pereira Aug 04 '14 at 17:46
  • I have some folders besides my codes. There are some files like images and etc. in them. I can't add folder besides my code in MATLAB compiler. I'm using compiler for create installation. So as you said maybe I can create a zip file that contains the folder. When user open the main GUI, this zip file will unzip. that's true? – Eghbal Aug 04 '14 at 17:50
  • I think Matlab is not the best tool to create installers. I would use WinRAR or Nullsoft NSIS Installer. If you want to create a installer with matlab, the easiest is creating a zip, embedding the zip into the executable, and unzipping - with Matlab's command unzip(filename) - the zip file in the folder specified by the user. – Daniel Pereira Aug 05 '14 at 06:31
  • To specify filename, just use the name of the zip, do not use pwd, or any other paths. Just unzip('installer.zip'). That should work. – Daniel Pereira Aug 05 '14 at 06:32