0

i have meet a problem when using coder to generate C coder. matlab function contains a sentences like

function [ B ] = fn1( A )
    a = A(:,2);
    B = a+1;
end

A is input parameter, 4x2 matrix.

i got c code:

void fn1(const float A[8], float B[4])
{
  int i0;
  for (i0 = 0; i0 < 4; i0++) {
    B[i0] = A[4 + i0] + 1.0F;
  }
}

B is not then 2nd column of A.

in matab "define input types", i changed row/column ,it still not working.

i'm using matlab 2016b. is there additional setting or advice to solve this problem?

thanks.

smdbh
  • 71
  • 3
  • 1
    Looks correct to me. If A is a 4x2 matrix, then the 2nd column elements are linear indexed 4,5,6,7 in a 0-based indexing scheme as in C, and you add 1 to each element to produce B. That is what the code does. – James Tursa Nov 04 '21 at 17:25

1 Answers1

0

KEYWORD: array layout. matlab array is column layout while C array is row layout. this mismatch causes the problem. matlab introduces 'array layout' option in R2019 or ealier, but it's not available in R2016.

smdbh
  • 71
  • 3