Why do I receive incorrect result from my model when I use the Inport block to specify my time and signal vector in Simulink?
Show older comments
In the model attached, I use the Inport blocks and divide the first input over the second. Using the following code, I initialize my time and signal vectors and simulate my model:
dt = 1/10;
time = [0:dt:5*dt]';
portvalues1 = [0 0 0 0 1 0]';
portvalues2 = [0 0 0 0 1 0]';
t = time;
u = [portvalues1, portvalues2];
sim('test', [t(1) t(end)], [],[t u]);
correct_output = u(:,1)./u(:,2)
simulink_output = yout
Where “dt” represents the step size of the simulation, “t” is my time vector and “u” is my input vector. After simulating it using the SIM command, I display both the correct output and Simulink output.
After running the code, I notice that I receive the following incorrect result when I compare the two outputs:
correct_output =
NaN
NaN
NaN
NaN
1
NaN
simulink_output =
NaN
NaN
NaN
1
1
NaN
This is the behavior in Simulink when time vector is defined using the following technique:
time = startTime : stepSize: stopTime
Accepted Answer
More Answers (0)
Categories
Find more on Sources in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!