running compiled matlab from matlab - 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.

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 simulink c code generation

I would like to import an existing C code (or any other text) into my generated code by Matlab simulink.I have some tasks that made in C,but in the future i want to develop in matlab.I work in simulink,and I can compile the models,but I want to use some special function what I previously wrote in C (because of pointer etc.).
The problem is that I don't know how to put in these texts into the model,and after the code generation these texts stay in the original format,and placed in the expected line.
And what I would like:
You can achieve this using the S-Function Builder. It allows one to create C code blocks, which get compiled with the model run. If using Code Generator, it gets inserted into generated code.
I generally use it to call functions from my external code or libraries, as in some Raspberry Pi Driver blocks I created.
It generates .c, .h and .mex files for each block and is quite clunky but does work!
BTW: If it's just to use an external pointer, you can happily use ImportedPointer/ExportedPointer for this. I find this handy for variables between generated code and container.

Link AnyLogic and Matlab

I was wondering if it would be possible that link AnyLogic to Matlab?
I need a way that call a function from Matlab to Anylogic.
At this level AnyLogic should be considered as Java application, and the question should be formulated as Link Java and Matlab. You may search for different Java libraries that establish connection with MatLab and Java app, allowing to pass commands from app to Matlab, and get the result. Example of such library — matlabcontrol. There is also example model.
UPD: Matlab provides Java API for AnyLogic, so you may directly use it within AnyLogic. In this case third-party libraries are not required. For this purpose you need to add engine.jar to the model dependencies, the .jar is provided with Matlab, it is located in:
matlab\extern\engines\java\jar
Here is the model that invokes Matlab using the respective examples from:
matlab\extern\examples\engines\java
I'm not sure which direction you are talking about.
calling a matlab function in anylogic:
Since Anylogic is based on Java, you could use the Java Runtime class, and do something like:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("C:\<a long path here>\matlab.exe" -nodisplay -nosplash -nodesktop -r "run('C:\<a long path here>\mfile.m');exit;"
after that you need to get the output from the process object pr and do your magic.
calling anylogic simulation in matlab:
have a look at : http://help.anylogic.com/topic/com.xj.anylogic.help/html/integration/Integration.html

Matlab/Simulink - Create S-function from DSpace Code

I know that it is possible to create S-function from C code that I provide.
But is it possible to create one S-function from C Code, which is generated from a Simulink Model for dSPACE ECUs, with low effort. The reason is, I am trying to test the dspace code with matlab/simulink.
Furthermore I'm aksing because the generated code from this simulink model consists multiple .c and .h files and I don't know how to integrate these files in one s-function block.
There are several methods of doing this. I suggest using the Legacy Code Tool as its structure helps to guide you through the process. You could also explore calling the function(s) from Stateflow or a Matlab Function block depending on the application.
With respect to multiple c/h files. I assume they will all need to be visible to Matlab through pointing to the source paths, but you should be able to identify the 'entry' function that you're interested in and utilize that in your model.

Compiling Simulink Code into .ELF object form

I have a simple model from simulink and I would like to generate code using the code generator in the simulink and then compile it using gcc into a .ELF object file. How can I proceed?
Thanks
You need the product called Simulink Coder (around matlab 2011b) or Real-time Workshop (for older matlab versions). Typing ver at the matlab command window will show what products and licences you have installed.
If Simulink Coder or RTW are installed, you use the menu Simulation->Configuration Parameters to set up the model for code generation.
If you have Embedded Coder you can set System Target File to ert.tlc, and this will produce a very concise main() routine to call your model code. Otherwise, use grt.tlc which produces a lot more bloat then ert, but is the only useful one available for on Windows.
There are a lot of options to go through and check - it really needs someone with a bit of experience to be present!
As you are requesting an ELF file, is this for an embedded system? If so, there is a lot more work to be done. If the target is not one of the already supported targets, then you need a target package, which will take either a lot of time and experience, or money to buy one.
Custom target development - a world of it's own:
http://www.mathworks.co.uk/help/toolbox/rtw/ug/bse3b2z.html