Main Content

Use External Functions with Matrix Input in a C Function Block

This example shows how to pass a matrix input to a C Function block and do row-major operations using external custom code.

open_system('mMatrixColumnSumExternalCode');

In this example, a matrix input is used by external custom code to calculate the sum of the each column of the matrix and the results are passed to the output block. The external function accesses input arrayarras row-major usingarr[r][c].

The custom code is called in theOutput Codepane of the C Function block.

The external source and header files are specified on theConfiguration Parameters>Simulation Targetpane.

For the matrix input, the size of the input symbol on the matrix table is specified as[r c], wherercorresponds to the number of rows in the matrix input andc对应的列数。

指定Default Function Array Layout

The external C function accesses input arrayarrusing row-major layout. To ensure the validity of calculations with MATLAB, go toDefault Function Array LayoutunderConfiguration Parameters>Simulation Targetand selectRow-major.