na_0021: Strings

ID: Title

na_0021: Strings

Priority

Strongly recommended

Scope

NA-MAAB

MATLAB Versions

All

Prerequisites

None

Description

The use of strings is not recommended. MATLAB® Functions store strings as character arrays. The arrays cannot be re-sized to accommodate a string value of different length, due to lack of dynamic memory allocation. Strings are not a supported data type in Simulink®, so MATLAB Function blocks cannot pass the string data outside the block.

For example, the following code will produce an error:

name='rate_error'; %this creates a 1 x 10 character array
name = 'x_rate_error'; %this causes an error because the array 
size is now 1 x 12, not 1 x 10. 

Note

If the string is being used for switch / case behavior, consider using enumerated data types

Rationale

  • Verification and Validation

  • Workflow

  • Code Generation

See Also

  • jh_0024: Strings

Last Changed

V3.0

Was this topic helpful?