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일

0 개 추천

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

Daniel Schmidt
Daniel Schmidt 2018년 3월 27일
Hi Birdman,
thank you for your answer and for the edited model. The enabled Subsystem looks very promising.
There is just one thing I don't understand in your edited model. The input port 1 of your way (labeled MYWAY) is fed by the output port 2 of my way (labeled YOURWAY). So essentially your version with the enabled subsystem uses the output of my version and thus also uses the memory block.
Best regards
Daniel
Birdman
Birdman 2018년 3월 27일

It uses the output of the first MATLAB function(labeled YOURWAY) but does not use the output of the Memory block. Please note that.

Daniel Schmidt
Daniel Schmidt 2018년 3월 27일
편집: Daniel Schmidt 2018년 3월 27일
"It uses the output of the first MATLAB function(labeled YOURWAY) but does not use the output of the Memory block"
And the first MATLAB function uses the output of the memory block as an input, therefore you still use the memory block. ;)
Birdman
Birdman 2018년 3월 27일
Ups yes, that is right. I will reedit the model later today.
Daniel Schmidt
Daniel Schmidt 2018년 3월 27일
Thank you so much for your effort :)
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개)

카테고리

도움말 센터File Exchange에서 Subsystems에 대해 자세히 알아보기

제품

질문:

2018년 3월 27일

댓글:

2018년 3월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by