na_0021: Strings in MATLAB functions
Control Algorithm Modeling Guidelines - Using MATLAB®, Simulink®, and Stateflow®
Sub ID Recommendations
NA-MAAB — a
JMAAB — a
Sub ID a
Assignment statements for strings shall not be used in MATLAB functions.
An assignment statement for strings is being used in the MATLAB function.
function y = fcn(u) %#codegen str = 'A'; for i = 1:u str = [str 'B']; end if strcmp(str, 'ABB') y = int16(1); else y = int16(0); end end
Sub ID a:
MATLAB functions store strings as character arrays. As a result, storing strings of different lengths in the same variable does not support dynamic memory allocation, which prevents the strings from being stored.
Consider using enumerated types when a string is used in a Switch Case block
Model Advisor check: Check usage of character vector inside MATLAB Function block (Simulink Check)
Introduced in R2020a