im using 'accumarray' function in my prgm.I need to convert my prgm to C code using CODER but 'accumarray' does not support this conversion.Is tre any means to convert it or any otr options?????pls leme know
1 次查看(过去 30 天)
显示 更早的评论
im using 'accumarray' function in my prgm.I need to convert my prgm to C code using CODER codegeneration but 'accumarray' does not support this conversion.Is tre any means to convert it into C or any otr options?????pls leme know
0 个评论
采纳的回答
Abhiram Bhanuprakash
2014-10-28
Hi Karthik,
You are right. The function 'accumarray' is not supported by MATLAB Coder, as you can see in the list here
To work around this issue, I have used functions which are supported by MATLAB Coder, and I have written a MATLAB script 'accarr.m', which seems to work (attached). I have written it in a way that it will only work for 1 D and 2 D arrays for 'subs'. I have tested it and it seems to give the same result as the MATLAB function 'accumarray'.
Following is an explanation of why I used some lines in the code:
1. siz = max(subs) is because the maximum value of 'subs' determines the size of the result. For example, if
subs =
1 1
2 2
4 1
2 1
4 2
Then the result should have 4 rows and 2 columns, right? max(subs) returns precisely 4 and 2, because the max function operates column-wise (as is the case with most functions in MATLAB).
2. 'numel' gives you the number of elements in an array/matrix. I am using numel(siz) to check if the result we want is 1 D or 2 D, in other words if 'subs' is 1 D or 2 D. Since siz = max(subs), if 'subs' is 1 D, siz will also be 1 D, and if subs is 2 D, siz will also be 2 D. You can also use size(subs,2) instead of numel(siz), if it is confusing to you. For information on 'size' function, check this out
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!