How to select elements from a vector repecting a condition in Simulink
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
here is my problem:
I have in input a vector of size 31, filled alternatively with zeros or doubles (e.g. [2 8 3 0 0 0 0 0 5 7...]). What i need to do is sum the different series of non-zeros values and output them in another vector, keeping zeros between those values. With the previous vector, that would give: [13 0 12...].
I also know that there will be a problem if the number of series isn't always the same, but i think i could find a trick to avoid that problem. I did that in a Matlab function embedded in my Simulink code, but I heared Simulink code was much more performant than Matlab for embedded systems.
Do you have any idea on how I could do this?
Thank you for your answers,
Josselin
댓글 수: 0
답변 (1개)
Niklas Nylén
2014년 4월 9일
편집: Niklas Nylén
2014년 4월 9일
Although it is possible to do what you want without using simulink blocks it is a bit tricky. You could start by attempting to speeding up the simulation by using the information found in this answer: http://www.mathworks.com/matlabcentral/answers/97224
댓글 수: 2
Niklas Nylén
2014년 4월 11일
It is probably difficult to avoid some kind of loop. I would start by just attempting to get variable length vectors to be assigned in a simulink for loop. After that it should just be a matter of which values that should be assigned to the output vector (i.e. assign to the vector if the current value is not equal to zero or if it is equal to zero and the previous value is not equal to zero.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!