Load Pretrained Networks in Matlab function block

13 views (last 30 days)
Bahadir
Bahadir on 10 Jun 2025
Commented: Bahadir on 29 Sep 2025 at 16:47
Hi,
I want use pretrained LSTM network in simulink matlab function block but ı get this error.
function y= fnc( Va,Vb,Vc,Ia,Ib,Ic)
input= [Va, Vb, Vc, Ia, Ib, Ic];
input=rescale(input);
XTrain = {input'};
net = coder.loadDeepLearningNetwork('alphabeta.mat');
output= predict(net, XTrain, 'MiniBatchSize', 1);
y=output{1};
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
For deep learning, the simulation target language must be set to C++. Function 'MATLAB Function' (#117.120.166), line 6, column 7: "coder.loadDeepLearningNetwork('alphabeta.mat')" Launch diagnostic report.

Answers (1)

Paul
Paul on 11 Jun 2025
Edited: Paul on 11 Jun 2025
According to the doc pages coder.loadDeepLearningNetwork and predict- (not recommended) and the error message this function might work (not tested)
function y= fnc( Va,Vb,Vc,Ia,Ib,Ic)
persistent net
if isempty(net)
net = coder.loadDeepLearningNetwork('alphabeta.mat');
end
input= [Va, Vb, Vc, Ia, Ib, Ic];
input=rescale(input);
XTrain = {input'};
output= predict(net, XTrain, 'MiniBatchSize', 1);
y = ????; % assign a dummy value to y that is of the same size and type of output{1}
y=output{1};
end
Also be sure to go to Model Settings -> Simulation Target -> Language and select C++ from the dropdown menu.
  1 Comment
Bahadir
Bahadir on 29 Sep 2025 at 16:47
I get this error.
Deep learning code generation using MinGW64 Compiler (C++) toolchain is not supported for mkldnn target. Function 'MATLAB Function' (#141.61.100), line 5, column 11: "coder.loadDeepLearningNetwork('32.mat')" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of 'Simulink_Doktorailkdosya/MATLAB Function'.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'Simulink_Doktorailkdosya/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'Simulink_Doktorailkdosya/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!