shweta
shweta

Reputation: 1

stand alone matlab exe does not work

I have a MATLAB code that works but when I convert it into an exe, it gives me an error saying that it can't find an m-file that I am running within that code. Here is the code.

clear all
str = sprintf('MyInput.txt');
fp = fopen(str,'r');
N= fscanf(fp,'%d',1)*2;
for i=1:N
    a=sprintf('phtoh0_%d',i);
    b=sprintf('phtoh0_%d.mat',i);
    run(a);
    save(b)
    clearvars -except N fp str
end

The error is phtoh0_1 not found. Any help is appreciated.

Upvotes: 0

Views: 307

Answers (1)

Andrew Janke
Andrew Janke

Reputation: 23898

You cannot use run() usefully with compiled Matlab code. Because it's a dynamic invocation, the Matlab Compiler won't see the dependency on the function you're calling, so it won't be picked up for compilation. You'll need to change it in to a function and use either explicit references, compiler pragmas, or compiler options to force it to be included in the compiled code. And then call it as a regular function using str2func instead of run.

Even if you get the plain Matlab phtoh0_1.m file in a directory the compiled exe is at or cd'ed to, the compiled Matlab program won't run it unless it was included in the original compilation. The Matlab Component Runtime will refuse to run non-obfuscated Matlab code.

Upvotes: 2

Related Questions