Simulink Coder .exe dynamically importing data from .mat/.csv or Access Database

조회 수: 2 (최근 30일)
Martin
Martin 2016년 2월 5일
답변: zheng 2020년 1월 7일
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
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
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개)

zheng
zheng 2020년 1월 7일
Do you have solved this problem?Can you help me?Thanks

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by