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
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!