Vector input for MATLAB function block

조회 수: 8 (최근 30일)
Daniel Schmidt
Daniel Schmidt 2018년 3월 27일
댓글: Daniel Schmidt 2018년 3월 28일
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에서 Subsystems에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by