There is nothing wrong with code. I know how to do 2 cycle square wave and not 10 Khz square wave. The code can do 2 cycle square wave . but the assignement required 10 khz.
So what properties would a 10 kHz square wave have in matlab that your two cycle squarewave does not have? If you say on your plot that the horizontal axis represnets 200 microseconds and that each division in your array represents (200/256) microseconds then you are home free. What is the major malfunction here? I don't get it.
The problem with generating the square wave in Matlab in the way above is that the result is retained within a matrix. Therefore for an arbitrarily long signal, you need an arbitrary sized matrix.
You need to specify what the signal length would be and code accordingly. What is the required signal length?