Function Call - MATLAB & Simulink (original) (raw)

Main Content

This example shows how to generate a function call by adding a subsystem, which implements the operations that you want.

C Construct

void add_function(void) { y1 = u1 + u2; }

Procedure

1. Open example model ex_function_call.

The subsystem has two inputs and returns one output.

Selecting the Treat as atomic unit parameter enables parameters on the Code Generation tab. The Code Generation tab provides these customizations:

2. To build the model and generate code, press Ctrl+B.

Results

In ex_function_call.c, the function is called from ex_function_call_step:

/* Model step function / void ex_function_call_step(void) { / Outputs for Atomic SubSystem: '/Add_Subsystem' */ add_function();

/* End of Outputs for SubSystem: '/Add_Subsystem' */ }

The function prototype is externally declared through the subsystem file, add_function.h:

extern void add_function(void);

#endif /* add_function_h_ */

/*

The function definition is in the subsystem file add_function.c:

void add_function(void) { /* Outport: '/y1' incorporates:

See Also

Function-Call Subsystem

Topics