mp_0040: Using the return value of a function
Since R2024b
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB®, Simulink®, and Stateflow®
Sub ID Recommendations
NA-MAAB — a
JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The return values of functions shall be assigned to variables before use.
ret1 = func1(arg1); ret2 = func2(arg2); ret = ret1 + ret2;
ret = func1(arg1) + func2(arg2);
Rationale
Sub ID a:
Although it is not syntactically incorrect to use the return values of functions directly, the results may vary depending on the order of the function evaluation.
Readability improves where the return values of functions are assigned to variables before use, rather than where the return values are used directly in operations.
Verification
Model Advisor check: Check for utilization of the return value of functions (Simulink Check)
Last Changed
R2024b
Version History
Introduced in R2024b