2

How do I use deploytool to get an executable file from a .m function and use it?

say, I have a .m names foo, here is the code:

function product = foo(array_a,array_b)
product = array_a.*array_b
end

now I use deploytool to generate a foo.exe, how can I use it with the same workspace vars, AKA array_a and array_b?

Regards

Coderzelf
  • 752
  • 3
  • 10
  • 26

2 Answers2

3

I got your code to work by just supplying the executable file with variables.

I first ran mbuild -setup. I have your file, called foo2.m:

function product = foo(array_a,array_b)
if ischar(array_a)
array_a = str2num(array_a);
end
if ischar(array_b)
array_b = str2num(array_b);
end

product = array_a.*array_b
end

The only difference is I ensured that the input are processed as numbers, not strings. Then, I compile:

mcc -mv -R -singleCompThread -N -p optim -p stats foo2.m

(A good explanation of this command is here: MCC example. I used the link to help me get it working.)

Then, just execute the function.

./run_foo2.sh /usr/local/MATLAB/R2011a/ 1 2

....

product =
 2

Make sure you specify the location of the compiler libraries as the first argument, then array_a and array_b as the 2nd and 3rd arguments.

I first got an error when I tried to run the executable: error while loading shared libraries: libmwmclmcrrt.so.7.15: cannot open shared object file. I fixed this by finding the library file path (using find . -name "libmwmclmcrrt.so*"). I then corrected the library path I was supplying as the first argument when I called the executable.

Community
  • 1
  • 1
David_G
  • 1,127
  • 1
  • 16
  • 36
1

You can use eval to convert strings to other data types, such as arrays. See here for more details.

Also, pcode could be another way, if you want to protect your source code.

imriss
  • 1,815
  • 4
  • 31
  • 46