Initialize buildable Simulink Model with parameters from SQLite Database

6 views (last 30 days)
Context: I have a huge Simulink Model that is going to be used for automated simulations on a Debian 10. Therefore it has to be buildt as standalone C-Code using the Matlab Coder. This code is then called to start the simulation.
What I need: I need to find a way to initialize my buildt model with ~500 parameters. These change with each simulation run and are stored in a SQLite file. The goal is to have parameters written to the database, then start the Model wich reads the parameters from SQLite during initialization (presumably using the InitFcn Model Callback, although im open to alternatives).
What I have tried:
1. Direct SQL interface: I tried to use a direct Matlab-SQL interface such as JDBC (since i dont have access to the Database-toolbox) but those are not supported for Code generation.
2. Write a C-function that reads the SQLite file, then call the function during initialization in the InitFcn Callback using coder.ceval like this:
data = 0;
err = coder.ceval('read_function',4, 2, 12, coder.wref(data));
parameter = data;
Problem here is that coder.wref is not supported in Matlab and therefore doesn't work in the InitFcn. (Please correct me if Im wrong:) This only seems to work inside a Matlab-Function-Block:
Error evaluating 'InitFcn' callback of block_diagram 'Model'.
Caused by:
The coder.wref function is not supported in MATLAB.
So my problem with the second approach is, that i cant call the C-function during initialization.
3. Using a Matlab-function-Block to read the parameters isnt really an option, since i would have to route all the signals out wich makes maintaining and further development of the model really hard. Also my suggestion is, that the model would not even run because the parameters are needed to initialize the model.
Questions:
  1. Is there a way to make one of the above approaches work? If yes, how? Where is my mistake?
  2. Is there another (simpler) option to pass tha data as an array or struct to my model?Database looks like this:
Identifier Default
latitude 52.5
longitude 13.4
electricity_consumption 4000.0
ventilation_stream 50.0
PV_peak 30.0
PV_orientation 0.0
heatpump_exists 1.0
hotwater_consumption 1000.0
.
.
.

Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!