Vector input for MATLAB function block

8 次查看(过去 30 天)
Hello everyone,
I've been struggling with this problem for a while now and it's beginning to drive me mad:
I have a Simulink MATLAB function block that is supposed to perform some calculations with the last 100 values of a signal. Is there a way to dynamically store the last 100 values of said signal and feed it as an input into the MATLAB function block without using 100 inputs and thousands of memory blocks?
Best regards,
Daniel
  1 个评论
Daniel Schmidt
Daniel Schmidt 2018-3-27
I think I found a solution for my problem now. Basically, I introduce a second MATLAB function block to create and store the values.
Since I found this question a couple of times online, I uploaded an example for the calculation of a moving average using this method.
The disadvantage of my solution is, that the vector size (or time constant) needs to be defined directly inside the fcn block but that's fine for my purpose.
Of course, I'm always open for other suggestions. Maybe someone has a more elegant solution?!

请先登录,再进行评论。

采纳的回答

Birdman
Birdman 2018-3-27
Well, although your problem is ok, usage of Memory block always increases the chance for system to fail if the complexity of your system increases. The best way to hold the value of a signal is to use Enabled Subsystem and that is what I did. I also kept your way and made a comparison. My way also works, see if that helps to you. Notice how I used the Pulse Generator. I also changed the solver type to variable-step since I wanted both your way and my way to take the same step size while solving.
  7 个评论
Birdman
Birdman 2018-3-28

I changed the Memory block with Enabled Subsystem block this time only. Run it and see the results.

Daniel Schmidt
Daniel Schmidt 2018-3-28
Thank you for the new model. Everything works as intended. Btw, with the delay block, your model even works without the enabled subsystem.
I am going to mark my question as solved. Have a nice day and thanks again.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Schedule Model Components 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by