Simulink Coder .exe dynamically importing data from .mat/.csv or Access Database
2 次查看(过去 30 天)
显示 更早的评论
Good Morning!
I`m actually having serious troubles getting my project to work. (all Simulink with some scripts for data import)
Point 1: Generate a standalone .exe that can be run on a separate PC without Matlab Simulink - works so far
Point 2: Read data from an Access DB - perform the simulation with this input data and write the results back into the Access DB
DB or .mat/csv -> (start of simulink coder/rtw generated .exe file) -> Read data into input struct -> perform simulation/calculation in SIMULINK! -> generate output struct in workspace -> write output struct (end of .exe file)-> DB
Therefore I have a ReadDB.m(InitFcn call)script generating a struct including all needed parameters for the simulation, then the simulation is performed and the data is written back into the database using a script(StopFcn call) that writes the "output-struct" in the workspace back into the database.
As long I`m in the opened Matlab environment pressing "run", this really works perfect. Reading, calculating and writing back the results into the database.
As soon I generate the .exe using the Simulink Coder (what works fine so far) it is not working anymore. It looks like, that Simulink is calling the InitFcn during the compilation, not "compiling" the ReadDB.m script, but calling it and compiling the model with the recevied result.
Finally the .exe is working, but whatever data in the DB is changed, it has no effect on the result, the result is always the one, that comes from the data read during the compilation process.
To solve this problem I went a few steps further, I inserted a Matlab function block that is calling the ReadDB.m hoping it would compile the "function" not the "function result" into the .exe.
Sadly it does not :/ ... first it wasn`t even possible to get it to work, after some tries using extrinsic stuff it worked, but -> exctrinsic function calls can`t be compiled with simulink coder into an executable.
Failed again ...
The last option to get a workaround was instead of using the DB, using .mat files.
Just a simple source.mat read by "from file" library block, containing just the value X=5, multiplied by 2 in the Simulink model, written by "to file" into output.mat.
In fact I have the same issue here. If I exchange the .mat file against one where X=10 I receive an output.mat containing the value 20, am I using the file where X=5, I receive an output.mat file containing the value 10.
In Simulink pressing "run" this works pretty fine, but as soon I generate an .exe file, the result in output.mat is always 10. Again the .mat file is loaded during compilation and the result is a hardcoded input compiled into the .exe file.
How is it possible to generate an .exe, that can handle different input files/DB datasets that are structural identical but contain different values.
The target would be to have the DB data, csv, or mat file, for lets say a 2litre engine, start the exe, and calculate the results for it, and some minutes later exchange that input data/mat against the data of a 3litre engine, and receive the according calculation results for this one.
Is there maybe just a compiler setting that would fix this issue?
To use Simulink for the calculation is a must have.
I would really appreciate your help!
Thanks a lot!
BR Martin
2 个评论
Barath C
2016-10-19
Hello Martin, I am in the same soup you were in Feb 2016. Did you find the solution to this problem? If so, please help. This code generation and code - data separation is driving me nuts!
Thanks, Barath
Ji Gu Seo
2017-4-4
I recommend this example. 'Run Batch Simulations Without Recompiling Generated Code' https://www.mathworks.com/examples/simulink-coder/mw/simulinkcoder-ex72631586-run-batch-simulations-without-recompiling-generated-code
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!