Can we generate PN codes (maximal length sequence) using this technique in Matlab where L is the PN length?
If yes, why?
This will just create a random sequence of 0 and 1. In order to create a maximum length sequence you need a primitive polynomial as a generator. See for example https://en.wikipedia.org/wiki/Primitive_polynomial_(field_theory)