MATLAB: Reshape a matrix with a divisible of 10….

reshape

i wanted to reshape my a matrix of size 1*N into 10 rows N/10 columns… but when N is not divisible by 10 i get error… how can i rectify the error?? either pad it with zeros to get a number divisible by 10 or get the previous number divisible by 10….
that is if my matrix
A = 1 * 100
i need output B to be 10*10 output
but if A = 1*111....
i get error, so i want to convert
A to 1 * 120 and get B = 10*12 or
change A to 1*110 and get B = 10*11 new output....
please do reply me….

Best Answer

r = 10;
out = reshape([A(:);nan(mod(-numel(A),r),1)],r,[])
ADD
out = reshape(A(1:fix(numel(A)/r)*r),r,[])