Matlab compiler indicator flag - matlab

Hi I use Matlab code that sometimes is compiled.
Can I check that inside the code?
for example
if compiled_with_mcr
then
end

You can use the function isdeployed. This returns true when called within an application compiled with MATLAB Compiler, and false when called from within live MATLAB.

Related

Alternative to 'evalin' with MATLAB App Designer

I'm creating an app that I eventually want to compile as a standalone application. The app constructs a GUI for a preexisting MATLAB program and I utilize the evalin function twice in the following manner.
First, I run a 'start' function as follows
evalin("base",'func.start')
This instantiates a number of variables which are necessary to run the GUI.
Next, I run the following code to read in one of the variables into the AppDesigner workspace.
fx = evalin("base",'fx')
I wanted to see if there was a deployable alternative to 'evalin' that could be compiled by the MATLAB Compiler. Any help would be greatly appreciated!

Matlab corrplot function stopped working

The weirdest thing happened, it seems as Matlab corrplot function just stopped working. I have a piece of code which always worked perfectly fine. Now the same code is throwing an error. When I try
corrplot(CE,'varNames',{'Diam.','Depth','Rad.','Thick','Thin'})
I get:
Undefined function 'corrplot' for input arguments of type 'cell'.
The function is not deprecated, meaning that probably your Econometrics Toolbox is no longer available. You can check for the available toolboxes in your MATLAB license by running ver. Additionally you should run
which corrplot
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\econ\econ\corrplot.m
To show you whether it is around somewhere. I reckon something went wrong with the toolbox installation, so you should check whether you still have a valid license and, if so, reinstal the toolbox.
You might also have a variable called corrplot (which corrplot tells you whether that is the case) although in my case the error then is:
CE = [1:10].';
corrplot=1;
corrplot(CE,'varNames',{'Diam.','Depth','Rad.','Thick','Thin'})
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
which corrplot
corrplot is a variable. % Not good, you didn't want that.
Clear the variable with clear corrplot and check where in your code it creates this variable and rename it.

Checking the functions that need to be used by a script in Matlab

I have a package of code that's been written by someone else. I am running a script, which calls some functions, which in turn calls some more functions, etc. I would like to get the list of functions that are not MATLAB built-in functions but are a part of the package.
I tried using matlab.codetools.requiredFilesAndProducts('file.m'), which gives me a list of such functions, but not all the functions. I can see when I look at the code that there are many more functions called by a function in the script. Does this command only show 'first-level' functions? How can I get the full list?
This function performs well, but isn't guaranteed to get all files. Works fine for me though
http://www.mathworks.com/matlabcentral/fileexchange/15484-recursively-get-file-dependencies-of-a-given-function/content/getFileDependencies.m
Check out the function inmem which may help to solve this task. It displays all matlab functions that are currently in memory. Thus it lists those functions that have been recently called, i.e. that have been called since the last clear allor clear functions statement. Thus you would start with a clean workspace, execute your program, and check with inmem which functions are loaded into the cache and are not in the matlab install directory, those are the functions you are interested in.
You may also use the command-line helper disp-inmem that was scripted to (half-)automate this task.

running compiled matlab from matlab

I am trying to run compiled MATLAB code (by mcc) from inside MATLAB in a way that I can avoid using another license that is required by the compiled code. We need this because we run this same specific code part again and again and execution is stuck due to license waiting. We don't want to buy tons of this specific license just to mass run the same part. Is there any way to do this? tutorial?
Is it possible to compile a .m file to dll/so and wrap it like a mex and call it from MATLAB on the fly? How would I pass and retrieve complex arguments?
According to
http://www.mathworks.de/products/compiler/description3.html
creating shared libraries should well be possible.
Concerning passing and retrieving complex arguments:
If you plan to use mex, I'd assume you should be able to call the shared-library "main"-function with any arguments you'd like, using the mxArray type that you'll have to use anyway.
To run the MATLAB-compiled code in MATLAB, you want codegen, part of the MATLAB Coder. See this blog post on generating C code from MATLAB. The alternative, deploying code with mcc/mbuild and then reloading it into MATLAB with loadlibrary is rather contorted, and I wouldn't advice it.

Undefined function or method 'nanvar_base' in Matlab

Somehow my Matlab does not has the function nanvar_base, needed to use the function ttest2 to calculate the t and p value of two sample data. How do I install that function? Is it missing to anyone else?
I had this same issue, the ttest2 function calling a nanvar function from SPM rather than the MATLAB statistics folder. A simple fix is going into 'change paths' in MATLAB and moving the SPM paths to the bottom of the list.
The function ttest2 is part of the statistics toolbox.
However, when I try to edit it, it does not show any calls to nanvar_base.
Did you perhaps try to edit it yourself, and in the process made a mistake? If this is not the case, try edit ttest2 and see where it is located and show the line with the call to nanvar_base.
This function isn't part of MATLAB or any of its toolboxes/add-ons. It must be custom functions. There is a function call nanvar however, in the Statistics toolbox and also in the Financial toolbox. Is this maybe the one you're after? If so, do you actually have the Statistics Toolbox and/or the Financial Toolbox?
the problem is probably another toolbox (like SPM) getting in the way, with their own 'nanvar' function.
Move SPM to the bottom of the path definition list, or remove it completely.
In general moving SPM have a lot of conflicting functions, so always make sure their path is at the bottom.
I had the same issue when calling the function nanvar, and realised that there was a conflict with a function with the same name in the Fieldtrip toolbox (this Fieldtrip function calls nanvar_base). After removing the Fieldtrip/src folder from my paths, it worked fine.