Compile Matlab files with Load command

1.6k Views Asked by At

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?

2

There are 2 best solutions below

0
On

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.

0
On

Try this:

wd = cd % Gets the current directory

load([wd '\filename'])