# 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일)
karthik 2014년 7월 7일
답변: Abhiram Bhanuprakash 2014년 10월 28일
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

댓글을 달려면 로그인하십시오.

### 채택된 답변

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

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by