MATLAB: Elements of matrix in matlab

matrix elements

Hello I have a matrix as shown in attachment here. Is it possible to write such a program that it will count it elements from left to right but not from top to bottom. Example can I write it as
[0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0]
instead of writing it as
[0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

Best Answer

>> vec = [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0];
>> mat = reshape(vec,4,[]).'
mat =
0 0 0 0
0 0 0 0
0 0 0 0
1 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 1 0 0
And to convert back again:
>> reshape(mat.',1,[])
ans =
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0