Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to know if an mcc-compiled MATLAB function is called in MATLAB or via standalone application?

I have a MATLAB function that has been compiled into a standalone application with mcc. When the user works with the function through the standalone application, output arguments are not used and instead I would like to ensure that the user gives an address to an output file as an input argument.

For instance, say my MATLAB function myFunc is defined like this:

function out_mat = myFunc(nElem, varargin)
save_file = false;
if nargin == 2
    save_file = true;
    add_to_file = varargin{1};
end
out_mat = rand(nElem);
if save_file
    % Write out_mat to address add_to_file....
end
end

When called in MATLAB, the user can define an output address (add_to_file) or not. It is up to the user and I do not care! But if the user is using the standalone executable, I want to make sure that the user actually defines add_to_file. So basically I want to add a condition like this to my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if call_in_matlab
    narginchk(1,2);
else
    narginchk(2,2);
end

How do I check if call_in_matlab is true or false? In other words, how can I tell in a function is called through its compiled standalone application or in MATLAB?

>Solution :

There are some functions in MATLAB to support Compiler-generated stand-alone programs. See the documentation. In particular, you want isdeployed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading