MATLAB: Storing a binary number with leading zeros in a struct field

arrayleading zero

I want to store an integer(a binary number) with a specified number of digits in an array, but when enter them into a field, the leading zeroes are cut off. I originally enter them as a normal integer, and then convert the entire array with dec2bin. This works for the most part, but the leading zeros are cut off from the smaller values. For this function to work I need the entire array to have entries of the same length. I have tried to enter the binary numbers directly, but it still cut the leading zeros off.

Best Answer

dec2bin() has an optional second input argument which is the minimum number of bits to use.