Load Pretrained Networks in Matlab function block

5 ビュー (過去 30 日間)
Bahadir
Bahadir 2025 年 6 月 10 日
編集済み: Paul 2025 年 6 月 11 日
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.

回答 (1 件)

Paul
Paul 2025 年 6 月 11 日
編集済み: Paul 2025 年 6 月 11 日
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.

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by