How to select elements from a vector repecting a condition in Simulink

2 次查看(过去 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

回答(1 个)

Niklas Nylén
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 个评论
Josselin
Josselin 2014-4-9
Hi,
thank you for your answer.
Do you know happen to know if a Matlab embedded function could cause the malfunctionnment of a program in an embedded system using simulink code?
Just to be curious, how would you proceed, roughly, to do it the tricky way using only simulink?
Niklas Nylén
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by