I'm not sure if a user defined MATLAB function is executing or not in Simulink.

1 回表示 (過去 30 日間)
Pranav Joshi
Pranav Joshi 2022 年 5 月 20 日
回答済み: Paul 2022 年 5 月 20 日
To demonstrate the error, I am running a stripped down version of a neuron firing. Essentially, the variable v obeys the equation:
An image of the simulink model:
where I, the current, is just a square wave. Initially, and . When , becomes positive and v starts rising. In the simulink model a function "spike_checker" has been defined which makes flag = 1 every time v crosses 0.5 (a "threshold", lets say).
This value of the flag is used to trigger the integrator to reset the value of v back to zero (a "rising edge" on the flag variable resets the integrator). Now, the integrator is getting reset just as expected, but the problem is, when I see the value of "flag" on the scope, it shows that flag = 0 throughout. It never becomes 1.
But, it must become 1, or else what is triggering the integrator to reset?
I've attached the Simulink model file, and an image of the simulink model, as well as an image of the scope output.
So, the question is, why is the flag variable never becoming 1, yet the integrator is resetting the value of v?
  1 件のコメント
Midhulesh Vellanki
Midhulesh Vellanki 2022 年 5 月 20 日
I ran the model, v never croses 0.5. It might help to use the zoom tool to see the value closely.
Tip: you can put breakpoints in the matlab function for debugging purposes.

サインインしてコメントする。

回答 (1 件)

Paul
Paul 2022 年 5 月 20 日
Consider replacing the threshold crossing detection functionality in spike_checker with a self resetting integrator. Feed the state port into a Compare to Constant block, which then feeds the reset port.

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by