MATLAB: Do I receive an error when using the Demux block with Exported Global outputs in Simulink

simulink

I have a model 'test_error.mdl' with a Demux and the storage class setting of the outputs are 'Exported Global'. When I try to run the model, I receive the following error:
The signal attribute {StorageClass = 'ExportedGlobal'} specified on the line originating from the output port 1 of 'test_error/Demux' is invalid because the individual signals contained in this line are mapped to different memory locations. The StorageClass for this line must be set to 'Auto'.

Best Answer

The error message you observe is due to expected behavior. In order to specify a storage class other than "Auto" on the outputs of the Demux block, each of the outputs must have unique memory locations. Whereas, by default, the outputs of the demux block are elements of one contiguous block of memory. The attached workarounds allow the use of the 'ExportedGlobal' class by forcing the outputs of the Demux block to be stored in separate non-contiguous memory locations.
Workaround 1. You can use the 'Signal Conversion' block as shown in 'test_workaround.mdl'.
Workaround 2. Change the storage class of the input signal of the Demux block to 'Exported Global' i.e. to have a single memory location as shown in 'test_workaround2.mdl'.