Load Pretrained Networks in Matlab function block

10 views (last 30 days)
Bahadir
Bahadir on 10 Jun 2025 at 22:50
Edited: Paul on 11 Jun 2025 at 2:59
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 at 2:34
Edited: Paul on 11 Jun 2025 at 2:59
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.

Community Treasure Hunt

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

Start Hunting!