MATLAB: Do I obtain unexpected results from the output of a merge block when using Simulink

simulink

I have constructed a model which feeds a bus signal through two atomic subsystems, which each modify only part of the bus, and then output those modified bus signals to a merge block. I expect that both sets of modifications will be merged to create a single output bus with the combination of both changes to the bus.
My sources that feed the merge block (atomic subsystems) are not conditionally executed.

Best Answer

The problem that is most likely causing unexpected results is caused by the update of both signals feeding the merge in the same time step. Sources that feed merge blocks should be conditionally executed to remove any question about the update order of those systems. Ideally, only one source feeding the merge will execute in a given step.
The merge block literally allows two blocks to write to the same piece of memory. If the two source blocks write in the same step, the order that they wrote will determine the value of the merge at the end of that step. Unless the execution of the two sources to the merge is explicitly controlled, it is up to the default sorting order that will define how the memory is updated. This is a risky modeling practice and it is recommended that merge blocks ONLY be fed by conditionally executed sources. (triggered, enabled, function call, if-action, switch-case, subsystems, etc.)