Array accumulation in Coder project

Hello everybody! I have run into a dead end trying to find a way to replace the accumarray function in a project to be compiled in Coder. I end up with two large vectors, one giving the index, the other the numeric value to be added to the respective bin. Wrapping the thing into a for loop makes it slow. Furthermore the indices are quite evenly distributed, using e.g. unique(index) to modify the loop range does not improve performance by much. I would be glad if anyone has a good idea how to provide a fast binning which is compatible wit the Matlab Coder! Is there is a way to use histc for this?

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de Dic. de 2015

0 votos

You will probably need to write your own C code for that, and use coder.ceval()
However, the code you would use would essentially be a for loop, and if you wrote the for loop in MATLAB then MATLAB would translate it into C that should be efficient. Execution of the MATLAB Function Block might be slow but see example 3 to see how to code to test if you are in MATLAB or not (so you could use accumarray for that case.)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Dic. de 2015

Respondida:

el 14 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by