Array accumulation in Coder project
Ältere Kommentare anzeigen
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?
Antworten (1)
Walter Roberson
am 14 Dez. 2015
0 Stimmen
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.)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!