Random signls and clocktime in Simulink

6 次查看(过去 30 天)
Serbia
Serbia2022-8-10
Moved: Atsushi Ueno 2022-8-17
I have a problem in understanding a simple matlab property. If you have this simple model with the clock, a matlab function and a scope. Why does the fuction is just run every 0.2 seconds in the simulation time? Same when you use 100 as Stop time. Then the function will be run every 2 seconds. In between the random values generated by the funtion, Simulink connects the values linearzed. Next question is why is simulink generating alwys the same "random"signal? I want to implement a random noise signal in a bigger model, but i think i did not understand how it works.
function y = fcn(u)
y =rand;
end
  1 个评论
Atsushi Ueno
Atsushi Ueno 2022-8-10
Moved: Atsushi Ueno 2022-8-17
>Why does the fuction is just run every 0.2 seconds in the simulation time?
You must be using a Variable-step solver. It changes the step size during the simulation, reducing the step size to increase accuracy when model states are changing rapidly and increasing the step size to avoid taking unnecessary steps when model states are changing slowly. You can set expected step size as "Fixed-step size" below.
>Next question is why is simulink generating alwys the same "random" signal? I want to implement a random noise signal in a bigger model, but i think i did not understand how it works.
When you set the same seed value like zero as default, the rand function always return the same set of value. You need changing the seed value of the rand function.
Example: Each time you run the model, you will get different seed values depending on the time of day.
rng(sum(clock))

请先登录,再进行评论。

回答(0 个)

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by