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?

답변 (1개)

Walter Roberson
Walter Roberson 2015년 12월 14일

0 개 추천

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.)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 12월 14일

답변:

2015년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by