Why are predicted outputs different between Simulink and Matlab?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I saved trained dlnetwork as "net.mat" before this code.
load("net.mat","net_m");
open_system("simulink");
out = sim("simulink.slx");
x = dlarray(out.simout.Data,"TC");
y = predict(net_m,x);
t = [0:0.1:10];
figure;
plot(t,extractdata(y));
hold on
plot(t,extractdata(x))
hold off
With above code, the prediction was like blue line in 1st picture.
But in Simulink, prediction was like blue line in 2nd picture.
I'm sure that the filepath in predict block was "net.mat."
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1594681/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1594686/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1594691/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1594696/image.png)
0 Kommentare
Antworten (1)
Ben
am 9 Apr. 2024
Your network is a 1D CNN over the sequence. Simulink executes this network 1 time step at a time. To compare:
x = dlarray(rand(1,100),"CT");
y = predict(net_m,x)
This computes the 1D CNN over the sequence x. However in your Simulink system, you are only doing:
for i = 1:100
y(i) = predict(net_m,x(i));
end
To get the behaviour in Simulink you will need to create a buffer of the sequence/signal input to the Predict block. It might be possible to do this with a Tapped Delay block or a Buffer block. You may need to set the Simulink solver to a fixed step solver with appropriate time step.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!