How to select elements from a vector repecting a condition in Simulink
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Niklas Nylén
el 9 de Abr. de 2014
Editada: Niklas Nylén
el 9 de Abr. de 2014
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 comentarios
Niklas Nylén
el 11 de Abr. de 2014
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.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!