How can I use C code generated by Matlab coder?

조회 수: 4 (최근 30일)
Viktor
Viktor 2013년 7월 21일
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

채택된 답변

Kaustubha Govind
Kaustubha Govind 2013년 7월 22일
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.
  댓글 수: 1
Viktor
Viktor 2013년 7월 25일
Thank's for answer. I must learn more about C language
Viktor

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by