Main Content

Specify Global Cell Arrays at the Command Line

To specify global cell array inputs, use the -globals option of the codegen command with this syntax:

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

For example:

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

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

    Alternatively, use:

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

    The global variable g is a 1x3 homogeneous cell array whose elements are 1x1 double.

    To make g heterogeneous, use:

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

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

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

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

  • To specify that g is 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:

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

    Alternatively, use:

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

    The global variable g is 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