how can ı use "minibatchpredict(net,XTest);" command on simulink?
조회 수: 7 (최근 30일)
이전 댓글 표시
I trained a LSTM network.
How can I use "scores = minibatchpredict(net,XTest);" and "YPred = predict(net, XTest);" commands on Simulink?
댓글 수: 0
답변 (1개)
AJ Ibraheem
2025년 10월 6일
편집: Walter Roberson
2025년 10월 6일
The 'Stateful Predict' block might be what you're looking for. See https://uk.mathworks.com/help/deeplearning/ref/statefulpredict.html
댓글 수: 5
Spoorthy Kannur
2025년 11월 11일
Hi Bahadir,
You may try the following:
In Simulink, you can use your trained network for prediction inside a MATLAB Function block, but there are a few important details to ensure it behaves consistently with MATLAB, in your case:
function y = fnc(u)
persistent net
if isempty(net)
net = coder.loadDeepLearningNetwork('32.mat');
end
% Preprocess input the same way as during training
input = rescale(u);
XTrain = {input'};
% Perform prediction
YPred = predict(net, XTrain);
y = YPred{1};
end
1. Use a supported compiler: “minibatchpredict” ( https://www.mathworks.com/help/deeplearning/ref/minibatchpredict.html) is not codegen-compatible, but “predict” is (https://www.mathworks.com/help/deeplearning/ref/dlnetwork.predict.html). Select a supported compiler using (Visual Studio C++ is required; MinGW64 won’t work for deep learning code generation):
mex -setup cpp
2. Match data preprocessing: Apply the same scaling or reshaping you used during training (e.g., sequence dimension order).
3. Choose the right block execution rate: For sequence data, ensure the Simulink sample time matches your network input timestep.
If your results still differ slightly from MATLAB, check whether the MATLAB version of “predict” was run statefully or statelessly, since LSTMs maintain hidden states across calls — this can cause small output differences unless you reset or manage the network state manually in Simulink.
If this does resolve the issue, kindly reach out to MathWorks Technical Support for more help (https://www.mathworks.com/support/contact_us.html)
참고 항목
카테고리
Help Center 및 File Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!