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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Abhiram Bhanuprakash
Abhiram Bhanuprakash el 28 de Oct. de 2014
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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by