MATLAB: How to use C code generated by Matlab coder

c languagematlab codermatlab function

I'm trying to use a simple function generated from matlab coder on my PIC MCU. The matlab function is:
function [c] = myMult(a)
b = [1,2,4;
7,1,2;
8,4,9];
c = a.*b;
And the generated C code is:
/*
* myMult.c
*
* Code generation for function 'myMult'
*
* C source code generated on: Wed Jul 17 10:22:38 2013
*
*/
/* Include files */
#include "myMult.h"
/* Function Definitions */
void myMult(real_T a, real_T c[9])
{
int32_T i0;
static const int8_T b[9] = { 1, 7, 8, 2, 1, 4, 4, 2, 9 };
/* Mult */
for (i0 = 0; i0 < 9; i0++) {
c[i0] = a * (real_T)b[i0];
}
}
/* End of code generation (myMult.c) */
+ some other header files
So, how can I work with function:
void myMult(real_T a, real_T c[9])
Shouldn't be return value instead of void? Shouldn't be between () only one, input value? I generated C code same way like in webinar MATLAB to C Made Easy.
Thank's for replies
Viktor

Best Answer

The second input argument is actually a pointer, if you notice that it's passed in as real_T c[9], which is equivalent to real_T *c. Essentially, you need to allocate memory for a real_T vector of 9 elements and pass it in by reference. The output is assigned to that same variable.
Related Question