1

I'm new to Matlab compiler. I've got a simple GUI with a button that when it's pressed it calls a m-function (myfunction.m). This function simply return a number that is then showed with a message box. If I compile as:

mcc -m myfile.m

everything works fine. But if I add to myfunction.m this code:

load mydata.mat

The compiled file doesn't work, if I click the button then the message box doesn't appear. How should I treat load command when I compile with matlab?

Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
Titus Pullo
  • 3,751
  • 15
  • 45
  • 65
  • 1
    Are you sure you don't get an exception during the `load`? for example because the file you load is not there? Try to try/catch it and see. – angainor Oct 18 '12 at 14:27
  • The file .mat is in the same folder of .m files, so this is not the problem. – Titus Pullo Oct 18 '12 at 14:42
  • It could be the problem. When you launch the compiled application, its current working directory is probably going to be your home directory, not the directory the .exe file lives in. So the .mat file sitting next to your .m file won't be on the Matlab path and `load` won't see it. Regardless, use try/catch like angainor suggests and display the error message and it'll tell you what's wrong. – Andrew Janke Oct 18 '12 at 14:54
  • The error is: 'Unable to read file *.mat: No such file or directory'. It seems as you said. In fact when I use the complete path to load the file (/Users/myname/Desktop/projectM/file.mat) there is no error. How can I tell to search the file in the same folder of my executable or *.m file? – Titus Pullo Oct 18 '12 at 15:25
  • Using save command I discover that the executable file saves on "/" root folder. So probably load search, by default, on the same folder! How can I specify to search in the same folder of executable file? – Titus Pullo Oct 19 '12 at 14:30

2 Answers2

1

Try this:

wd = cd % Gets the current directory

load([wd '\filename'])
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
0

Inside Matlab I often locate the path with which:

tmp = which('myfile');
t2 = fileparts(tmp);
data_with_path = fullfile(t2,'mydata.mat');

Not sure if it works when compiled tough.

bdecaf
  • 4,652
  • 23
  • 44