na_0024: Global Variables

ID: Title

na_0024: Global Variables

Priority

Strongly recommended

Scope

NA-MAAB

MATLAB Versions

All

Prerequisites

None

Description

The preferred method for accessing common data is by signal lines. However, if required, Data Store Memory can be used to emulate global memory.

Example:

In this example, the same Data Store Memory (ErrorFlag_DataStore) is written to two separate MATLAB® Functions.

function EngineFaultEvaluation(EngineData)
%# codegen
	global ErrorFlag_DataStore
	if (EngineData.RPM_HIGH)
		ErrorFlag_DataStore = bitor(ErrorFlag_DataStore, HIGHRPMFAULT);
	end

	if (EngineData.RPM_LOW)
		ErrorFlag_DataStore = bitor(ErrorFlag_DataStore, LOWRPMFAULT);
	end
end
function WheelFaultEvaluation(WheelData)
%# codegen
	global ErrorFlag_DataStore
	if (WheelData.SlipHigh)
		ErrorFlag_DataStore = bitor(ErrorFlag_DataStore, WHEELSLIP);
	end

	if (WheelData.SlipHigh)
		ErrorFlag_DataStore = bitor(ErrorFlag_DataStore, LOWRPMFAULT);
	end
end

Rationale

  • Readability

  • Verification and Validation

  • Code Generation

  • Simulation

See Also

  • ek_0003: Global Variables

Last Changed

V3.0

Model Advisor Check

By Task > Modeling Standards for MAAB > Naming Conventions > Check MATLAB code for global variables

Was this topic helpful?