Use sub-function inside of an .exe file (generated by matlab)

I want to convert a script main.m,which uses a sub-function,into a standalone main.exe file. I tried using nested function inside the script but it doesn't work.The sub-function is being used multiple times during execution and it is quite large.Is there any way I can make this work? Maybe convert both script and sub-function into two exe files and make one call the other?
% script main.m %
. . .
Y1 = PolyApprox(S_initial1,S1,flag1,bound1);
Y2 = PolyApprox(S_initial1,S2,flag2,bound2);
. . .
% End of script %
system('main.exe') % run exe

4 Comments

??? Scripts cannot have sub-functions. Only functions and classdef can have subfunctions.
Matlab scripts can now support sub-functions (since R2016, I believe?), but I'm not sure if the Matlab Compiler will compile a script (see my answer below).
you are right. Do you have any idea how I can make this work? Is it even possible? Thanks!
Why not convert your script to a function? Especially considering that you plan to compile it, you surely cannot be counting on it changing variables in whatever workspace it happens to be executing in ?

Sign in to comment.

Answers (1)

Matt J
Matt J on 27 Dec 2017
Edited: Matt J on 28 Dec 2017
If your "script" really is a script (i.e., no function line header), then I'm not sure the Matlab Compiler will accept that as your main file. If you convert main.m to an actual M-function file, there's no reason why a sub-function should present problems.

Categories

Find more on Programming in Help Center and File Exchange

Products

Asked:

on 27 Dec 2017

Commented:

on 28 Dec 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!