How to embed a surrogate model in the Simulink modeling process, implement automatic code generation, and export it as an FMU model?

3 次查看(过去 30 天)
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?

回答(1 个)

Shishir Reddy
Shishir Reddy 2025-6-26
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:
  • Input x matches the dimensionality of your model.
  • treeModel.mat is on the MATLAB path or current folder.
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.

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by