If ayou can divide by n, you can actually only provide one RESHAPE argument.
To change the form into 2 lines:
b = reshape(a,2,[])
To change the form into 2 columns:
b = reshape(a,[],2)
Note that changing the form is done in columns, it fills the first column first, then the 2nd and so on. To get the desired result, you must convert it to 2 columns and then transfer the result.
b = reshape(a,[],2)'
You can put a check before changing:
assert(mod(numel(a),n)==0,'a does not divide to n')
source
share