- Input x matches the dimensionality of your model.
- treeModel.mat is on the MATLAB path or current folder.
How to embed a surrogate model in the Simulink modeling process, implement automatic code generation, and export it as an FMU model?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I hope to integrate data-driven surrogate models into Simulink, enabling the invocation of surrogate models (such as Kriging, decision forests, etc.) during Simulink modeling for simulation, analysis, and automatic code generation. Are there any good solutions or ideas?
0 Commenti
Risposte (1)
Shishir Reddy
il 26 Giu 2025
Hi @CoderMinga
As per my understanding, you would like to integrate data-driven surrogate models into Simulink. If a surrogate model is trained using MATLAB (e.g., with 'fitrgp', 'fitcensemble', or 'fitrtree'), then it can be used in Simulink by calling it from a 'MATLAB Function block'. This can be done as follows -
1. Train and save your model in MATLAB:
model = fitrtree(X, Y);
saveCompactModel(model, 'treeModel');
2. In Simulink, add a 'MATLAB Function block' and use the following code as a starting point:
function y = predictFromSurrogate(x)
persistent mdl
if isempty(mdl)
mdl = loadCompactModel('treeModel');
end
y = predict(mdl, x);
3. Ensure that:
For more information regarding MATLAB function block, kindly refer the following documentation https://www.mathworks.com/help/simulink/ug/what-is-a-matlab-function-block.html
I hope this helps.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!