Main Content

Specify Global Cell Arrays at the Command Line

To specify global cell array inputs, use the-globalsoption of thecodegencommand with this syntax:

codegen myfunction -globals {global_var, {type_object, initial_value}}

For example:

  • To specify that the global variablegis a 1x3 cell array whose elements have class double and whose initial value is{1 2 3}, use:

    codegenmyfunction-globals{'g', {coder.typeof({1 1 1}), {1 2 3}}}

    Alternatively, use:

    t = coder.typeof({1 1 1}); codegenmyfunction-globals{'g', {t, {1 2 3}}}

    The global variablegis a 1x3 homogeneous cell array whose elements are 1x1 double.

    To makegheterogeneous, use:

    t = makeHeterogeneous(coder.typeof({1 1 1})); codegenmyfunction-globals{'g', {t, {1 2 3}}}

  • To specify thatgis a cell array whose first element has type char, whose second element has type double, and whose initial value is{'a', 1}, use:

    codegenmyfunction-globals{'g', {coder.typeof({'a', 1}), {'a', 1}}}

    The global variablegis a 1x2 heterogeneous cell array whose first element is 1x1 char and whose second element is 1x1 double.

  • To specify thatgis a cell array whose first element has type double, whose second element is a 1x2 double array, and whose initial value is{1 [2 3]}, use:

    codegenmyfunction-globals{'g', {coder.typeof({1 [2 3]}), {1 [2 3]}}}

    Alternatively, use:

    t = coder.typeof({1 [2 3]}); codegenmyfunction-globals{'g', {t, {1 [2 3]}}}

    The global variablegis a 1x2 heterogeneous cell array whose first element is 1x1 double and whose second element is 1x2 double.

Global variables that are cell arrays cannot have variable size.

See Also

|

Related Topics