X = coder.nullcopy(A) copies type, size, and complexity of A to X, but does not copy element values. The function preallocates memory for X without incurring the overhead of initializing memory. In code generation, the coder.nullcopy function declares uninitialized variables.
So your source matrix B_mat is uninitialized. It could contain anything . Containing 0 is as valid as anything else. It could contain 0xDEADBEEF