I use Simulink Coder for C/C++ code generation from Simulink models, but when I connect a signal to a Scope block and build it for code generation scope doesn't open automatically. Is there a way to integrate Scope block in code generation so that it opens automatically running .exe file? Thanks in advance.
This cannot be done. Scopes are MATLAB figure windows, use MATLAB code in the background, and hence do not support code generation.
Assuming you are only interested in desktop simulation (i.e. not real-time code generation) then what you can do is write a MATLAB GUI that calls a Simulink Coder (RSIM target) generated exe (to run a simulation and store the results in .mat file), then deploy the MATLAB GUI using the MATLAB Compiler. It's far from ideal, but can be made to work.
Related
Hello I am new to the Omnet++. I was trying to run the Omnet from the Matlab. Is it possible to run the particular project and generate results in Omnet++ using the Matlab or any command and without actually going on the graphical interface for pressing run button in Omnet++?
From what I have read in the official documentation site (https://omnetpp.org/), it is a library for discrete event simulation. The library is writeen in C++.
It is possible to compile and use C++ code and results using the Matlab MEX-API. (http://es.mathworks.com/help/matlab/call-mex-files-1.html). This API provides a fairly easy bidirectional connection interface between Matlab and C++. It enables matlab to create data to be further processed in C++ and the show the results on matlab later.
Hope it is useful for you!
I am in the process of developing an SFunction and compiled submodel in Simulink, an SFunction that calls into a DLL compiled using Realtime Workshop. The problem is, once I compile the submodel once, execute it in native Simulink through the SFunction and the model finishes, MATLAB still keeps a handle to the submodel DLL. I cannot recompile the DLL until MATLAB is restarted, forcing the release of the DLL.
I have even gone so far as to see if ProcessExplorer could force closed the handle but it can't.
How do you bind the S-Function to the DLL? If you bind at link time then you could try to bind at runtime and explicitly release the handle in mdlTerminate. That way, MATLAB should never even know that you accessed the DLL. Of course this makes the actual interaction with the DLL from within the S-Function somewhat messier.
I think it would work if you just rename the actual DLL to something else and then recompile. I know it works for mex files. If this doesn't work, you can try this solution.
Is it possible to compile Matlab code into a stand alone exe? meaning being able to run the program without having to have matlab or the matlab runtime environment installed on the computer?
does it help that the code has no GUI and does not use any toolboxes? also, the only interaction the person has with the code is through the command prompt
You need MATLAB Coder to generate C/C++ code from your MATLAB code. Yes, it does help that you don't have any GUI. Your code also needs to be restricted to the subset of MATLAB language that is supported by code generation. As far as toolboxes are concerned, there are quite a few which are supported by code generation.
A few people have mentioned the MATLAB Compiler. This is indeed for deployment on a machine where the end user does not have MATLAB, but it does require the installation of the runtime environment (MCR or MATLAB Component Runtime), which is freely distributable if you have a license of MATLAB Compiler. This does allow you to compile GUIs, but anything that is compiled on Windows can only be deployed on Windows, Linux on Linux, etc... (unless things have changed since I last used it).
I want to package up an application in MATLAB for another team to use. They will have an appropriate version of MATLAB to run this application, but they might not necessarily have licenses for all the toolboxes used by the application.
Is there a way to "bundle" the toolboxes into the application so that they do not require expensive licenses to run it?
If not, is it possible to create a stand-alone/license independent MATLAB application a different way?
EDIT: Some of these applications might feature GUIs as well as command line interfaces.
To generate code that can be run by MATLAB, you need the MATLAB Coder. The codegen command will generate the executables that can be run in MATLAB. Loren of MathWorks has a nice blog post on the product.
Here is an example of how to use codegen to create a MEX function from MATLAB code.
One big caveat is that with MATLAB Coder, the complete functionality of MATLAB is not yet available for compilation. This is because the generated binaries do not require the MATLAB Compiler Runtime (MCR), which is essentially a headless MATLAB virtual machine. Instead MATLAB Coder generates C code that is truly standalone, but the code generation is somewhat limited as a result. Here is a description of the subset of functionality, and here are complete lists of functions supported. Most toolkit functions appear to be supported according to the categorical list.
If the required functions are not supported, then it will be necessary to use the Compiler to generate standalone libraries and roll your own MEX interface to those libraries, as MrAzzaman indicated. Another possibilities is to use the loadlibrary function to directly load the Compiler-generate libraries, although I have never tried this last option. If you can't successfully interface with these libraries back in MATLAB, the MATLAB compiler can of course be used to generate a standalone executable. The deploytool simplifies the process of packaging the code and its dependencies.
The MATLAB Compiler sounds like exactly what you need. Unfortunately, it is a separate Toolbox which you would have to purchase.
EDIT: I should note that this will compile your MATLAB code into an application/library, not MATLAB code. The other team would still be able to use it with MATLAB, I believe, but I don't think they would be able to see the code itself.
Im sure there are a thousand different posts on Maple vs Matlab, but i have a bit of a unique set of requirements and before i go off to learn one of the two i would like to know which one will do it best.
I have a set of data from an accelerometer recording an impact. I need to do the following:
fit a curve to the data
Find the equation for that curve
solve the equation listed at the link
http://upload.wikimedia.org/wikipedia/en/math/2/d/3/2d39556df1dbbd467dc914253e93cdb0.png
which solves for a family of curves,i.e the MAX under the interval.
I would like to do this as seamlessly with visual studio as possible. The GUI and all the other elements of the app are built in VB and I would like to keep it there. I know maple has a code generating part to it that will convert to VB, would it be able to handle something like this? Does Matlab integrate with Visual Studio well? I would be thrilled if there was an object i could place on the VB form which would facilitate the communication to and from the matlab or maple framework. Currently i have it working with R, however to do so i need to write the data to a file, launch the R script, wait for it to finish, return control to my VB app and take it from there. This process takes too long and since i do not have experience with multi threaded programming the GUI freezes up when control is passed to the script.
Any help or suggestions would be very much appreciated!
In your case I would choose neither of the two. You may have a look at Python Tools for Visual Studio. The blog post mentions support for NumPy & SciPy for .Net which gives you all the math power you need at hand well integrated in the .Net world.
EDIT:
By looking at matplotlib's gallery I'm tempted to say that matplotlib is on par with MATLAB.
MATLAB doesn't auto-generate VB code, but it can easily be called from a VB application without the indirection of writing a file. It has COM interface that can be called directly from within VB code. See this example from the MATLAB documentation to find out more.
To carry out the technical analysis you've mentioned, you would probably save time by using Curve Fitting Toolbox in addition to base MATLAB.
Note that the above method of connecting to MATLAB via its COM interface relies on there being a live copy of MATLAB present when the VB application is executed. If you need to share your application with people who don't have a copy of MATLAB, you can also create standalone COM components and .NET assemblies from MATLAB code that can be called in the same way by your VB code, but can be deployed freely to people without a MATLAB license - however, this requires an extra product, MATLAB Builder for .NET.