MATLAB: How to reshape a vector in a particular way

matrixreshapevector

Hi,
I want to reshape a vector of length L in a matrix of size [mxp] where m*p == L is not true always. Example: A is given and I want matrix B to be something as given below
A = [1 2 3 4 5 6 7 8 9 10]
B = [1 2 3 4; 2 3 4 5; 3 4 5 6; 4 5 6 7; 5 6 7 8; 6 7 8 9; 7 8 9 10]
Is there any possible way to use reshape or any other function to achieve it?

Best Answer

Well, without you telling us the rule to obtain that matrix it's not very easy to answer your question. One possible way:
A = [1 2 3 4 5 6 7 8 9 10];
B = hankel(A, A(1:4));
B = B(1:numel(A)-4+1, :)
One thing for sure is that what you want is not reshaping.