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 CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by