I had Simulink model and have generated C code from MATLAB. Basically Simulink Model has many function and one S-Function with file Extension .mexw32 (hex code). The process of C-code generation is working without any error. Now that I have C-code and header files of my application, I wanted to build the solution file(.bat file) from these files with Visual Studio.
When I tried to build the files then I am getting error as shown in picture 1.
What I conclude is, there is a problem with the .mexw32 file to build. I dont have source code (c code) for these S-function .mexw32 file. I think that could be the problem while building the solution.
Do I need source code to build the solution or that doesnt matter if I have it or not? Because only the .mexw32 file is causing the problem during buiding the solution.
Yes, you'll need the source code (or an equivalent .tlc file). A .mexw32 file will only run inside MATLAB.
Related
I have a Simulink model wihich reads some data from a .mat file using a "From File" block. For ilustration's sake I created the following simple system which has the same problem I'm experiencing with my original model:
I need to generate a C code to run the model on another PC that does not have MATLAB. I generated the code and compiled it to validate it and I noticed that the executable is not reading the .mat file. No matter what signal I put on the file, the executable runs the model using the signal available at the moment of the compilation. I even erased the .mat file and the executable ran normally. Why is this happening? it is supposed that the "From File" block is there to read a .mat file, but it is not fulfilling its purpose.
NOTE: I am using MATLAB R2012b and Simulink version 8.0. I am using the Embedded Coder target (ert.tlc) for the code generation. I tried using the Rapid Simulation target (rsim.tlc) and the executable worked properly, however the execution time was higher. So I want to find a way to use the Embedded Coder target to have a lower execution time.
I want to know can i use this code for my projects?
ftp://ftp.nodc.noaa.gov/nodc/archive/arc0032/0071189/1.1/data/0-data/AT003L11/RR_MOVED/FUNFUN/ODE23.C
it uses a include mex.h file in the beginning. what is that? what is that mex header doing there? can i just ignore that line and use the rest of the code in somewhere else?
I want to use the file in android NDK.
This file is meant to be compiled for Matlab to process. If you have Matlab installed you can compile it from the console. If not you will not be able to compile this by simply removing the include statement. Your best bet is to read through the code, understand what it is doing, and use it as an example for your own code.
I'm using MATLAB R2015a application compiler. After choosing my main m-file, MATLAB found some files required for application to run but after compiling and running my application, the compiled application can't find some specific m-files from an installed toolbox (third-party toolbox).
Now i want copy all toolbox files to target folder C:\Users\My_Account\AppData\Local\Temp\My_Account\mcrCache8.5\Program_70\DDM. DDM is my toolbox folder that MATLAB creating it automatically based on nested files as mentioned above. I want add other files to this folder. How can I do this? and is this a good solution to fix this problem?
What you're trying to do won't work.
When you compile an application with MATLAB Compiler, it finds all code that your main function depends on, encrypts it, and packages it into an executable that will later be executed against the MATLAB Compiler Runtime (MCR).
The MCR can only execute code that has been encrypted and packaged in this way - it is not possible to get it to execute a regular unencrypted MATLAB file. So dumping things into the temp folder that the MCR uses to unpackage code files will not achieve anything.
Instead try to figure out why, during the dependency analysis, MATLAB Compiler is not finding all the files that your main function depends on.
There are various reasons why that might happen - the dependency analysis is not perfect. For example, if your code calls eval('myfunction'), the dependency analysis will not find myfunction. I answered another question recently where another cause was the issue.
In these situations you can explicitly tell MATLAB Compiler that there is a dependency on myfunction, using the %#function pragma. Within the file that contains the hidden call to myfunction, at the top of the file (actually anywhere, but typically you'd put it at the top), put
%#function myfunction
MATLAB Compiler will then force that to be a dependency and include it in the packaging.
Alternatively, when setting up the packaging with mcc or in the deploytool app, you can just manually add myfunction to the package yourself (although this will then not find things that myfunction depends on).
How can I create a custom batch file for my code generated from Simulink model ?
I can see, if I edit and change my template make file from Configuration Parameter Dialog box, I can get the desired make file.
But I want a custom .bat file too, that calls this make file along with other commands.
I have some environment variable to set and run couple of scripts in .bat file, before compilation begins. Based on these outputs from script the code is to be compiled and linked.
Using Matlab Version: 2012b
Create a STF_wrap_make_cmd_hook that generates your desired modelname.bat file as shown in the example code
here (mathworks login necessary).
You will probably also need to write your own make_yourtarget.m file and edit the make command field shown in your screenshot to use that one instead of make_rtw.
Other hooks into the build process are described here, perhaps the 'before_make' will also be useful.
I'm getting message
Error in S-function 'project1_simu/S-Function': S-Function 'chiu_sfcn' does not exist
whenever i run my simulink file which contains s-function block diagram. Any tips to resolving this problem?
You need to compile the s function using mex.
Then the mex32 output file needs to be on the matlab path.
For an S-Function, you need to make sure your C, Matlab, or Fortran Code is where Simulink expects it to be. My guess is your code exists, but isn't in the directory simulink expects.
Right click on the S-Function Block in your Simulink Project -> Choose S-Function Parameters.
Click on the Edit button next to the S-function name.
It will probably tell you the S-Function source cannot be found. It will then prompt you to either browse for the code or open an editor.
If you can't figure out where this file is located and you have the code your best bet is to open the Editor from this dialog box.
From there just paste the code and save it as 'chiu_sfcn'. You don't need to put a file extension, or browse to a different folder. It should automatically save it in the right folder for you.
It is possible that your version of Matlab is newer
than the version of Matlab used to produce the S-function.
If this is the case, I believe that the S-function
must be recreated in a newer version of Matlab
in order to interface with newer versions of Matlab.