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 =
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
Best Answer