I want to create a customized block in Simulink where only input and output ports are defined and then add any other block like machine learning (if possible) to process the input and generate the output. I have searched a lot but the examples on MathWorks are very specific. I am looking after a very general solution where a simple and empty block with only input/output ports can be added and output is generated based on the input.
Thanks in advance,
D.
I used C S-function in Simulink real time. When compiling the model, the following errors occurred,
“mxCreateDoubleScalar”is not defined;
“mexPutVariable”is not defined;
<"mxSetCell_ is_ not_ supported_ in_ Simulink_ Coder ": undeclared identifier
[enter image description here][1]
I know that Simulink real time doesn't seem to support “mxCreateDoubleScalar”、“mexPutVariable”, but I don't know how to replace it, can you help me?
[1]: https://i.stack.imgur.com/xtiyo.png
I recommend you to work with executables. First you have to have installed a C/C++ compiler. I recommend you to install minGW (you can get it on the AddOn of Matlab).
Then, you have to initialize all the variables that you are using on the s-function.
For last, when you want to make a "mex" with your model and s-function, check the command line to mex all files. I had the same problem 2 years ago and I was able to create a real-time application and run it.
Here you have how to use the mex function mex function
Here you have the information about the C/C++ compiler C/C++ compiler
Here you have the information about how configurate your .mdl or .slx Simulink Real-Time
I suggest you to post this question on the Matlab's forum, possibly they could help you better.
BR.
PD: If you have .h files linked with your .c file, make sure that on the mex command line you are linking all this files.
I was wondering if there is a way to create a '.exe' file from ' .m' file in MATLAB, such that it can be run in machine which does not have MATLAB (like it can be done in C, C++).
I know writing a MATLAB function is one way, but I am not sure if it can run in machine without MATLAB.
Also I would like to hide my code and just create a script which can be run by a user using his own data files.
The Matlab Compiler is the standard way to do this. mcc is the command. The Matlab Runtime is required to run the programs; I'm not sure if it can be directly integrated with the executable or not.
If you have MATLAB Compiler installed, there's a GUI option for compiling. Try entering
deploytool
in the command line. Mathworks does a pretty good job documenting how to use it in this video tutorial: http://www.mathworks.com/products/demos/compiler/deploytool/index.html
Also, if you want to include user input such as choosing a file or directory, look into
uigetfile % or uigetdir if you need every file in a directory
for use in conjunction with
guide
Try:
mcc -m yourfile
Also see help mcc
If your code is more of a data analysis routine (vs. visualization / GUI), try GNU Octave. It's free and many of its functions are compatible with MATLAB. (Not 100% but maybe 99.5%.)
mcc -?
explains that the syntax to make *.exe (Standalone Application) with *.m is:
mcc -m <matlabFile.m>
For example:
mcc -m file.m
will create file.exe in the curent directory.
It used to be possible to compile Matlab to C with older versions of Matlab. Check out other tools that Matlab comes with.
Newest Matlab code can be exported as a Java's jar or a .Net Dll, etc. You can then write an executable against that library - it will be obfuscated by the way. The users will have to install a freely available Matlab Runtime.
Like others mentioned, mcc / mcc.exe is what you want to convert matlab code to C code.
The "StandAlone" method to compile .m file (or files) requires a set of Matlab published library (.dll) files on a target (non-Matlab) platform to allow execution of the compiler generated .exe.
Check MATLAB main site for their compiler products and their limitations.
I developed a non-matlab software for direct compilation of m-files (TMC Compiler). This is an open-source converter of m-files projects to C. The compiler produces the C code that may be linked with provided open-source run-time library to produce a stand-alone application. The library implements a set of build-in functions; the linear-algebra operations use LAPACK code. It is possible to expand the set of the build-in functions by custom implementation as described in the documentation.
I have seen this documentation but I really couldn't be sure what exactly is "external mode".(SS_SIMMODE_EXTERNAL)
Why am I worried?
I have a simulink model that contains a sfunction. Inside This sfunction there is a mexCallMatlab command. So, this will only work if the model is running under matlab environment.
Otherwise, if running in a compiled mode, this command will not work.
That leads us back to the original question: does "external mode" differentiates whether the model is running under matlab environment or compiled mode?
I would like to call some Matlab functions using Erlang.
I have two separate network models (one comms/control, one energy)
Ideally I would like an Erlang process to send a message which causes some Matlab code to run. After the Matlab code has finished it must notify Erlang.
What is the simplest way of doing this?
I am running Windows 7. Matlab appears to require use of Microsoft Component Object Models which do not seem to be commonly used with Erlang - hence my question...
Thanks,
You can run Matlab statements from the command line:
matlab -r "statements"
Erlang gives you the opportunity to open ports to execute OS commands. Combining the two features should do the job for you. Have a look to the os:cmd/1 function. For example, you could simply do:
os:cmd("matlab -r STATEMENT").