MATLAB: Conversion of an Matrix

homework not originally tagged as homeworkmatrixmatrix conversion

I have an array : A = [0 3 5 7 8 9 1 3 4 0]. I want to convert it into 1×3 matrices such as [0 3 5], [3 5 7], [5 7 8]…[3 4 0] and so on.
My code is:
clc
A = [0 3 5 7 8 9 1 3 4 0];
B = zeros(1, 3);
r=1;
c=3;
for i = r:c
for k = 1:3
B(k) = A(i)
r=r+1;
c=c+1;
end
end
But it doesn't seem to be working correct. Can somebody help?

Best Answer

Use the hankel (link) function to create a Hankel matrix:
A = [0 3 5 7 8 9 1 3 4 0];
B = hankel(A,A(1:4:end))
B =
0 3 5
3 5 7
5 7 8
7 8 9
8 9 1
9 1 3
1 3 4
3 4 0
4 0 8
0 8 4