Converting Vector to matrix.

Hello!
I want to convert vector:
V = [1 2 3 4 5 6 7 8 9]
To
V1 = [
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9 ]
Is there a Matlab command that will let me do this? or this needs to be coded?
Thanks
KIB

 채택된 답변

the cyclist
the cyclist 2011년 8월 6일

0 개 추천

It wasn't clear to me how general V might be, but I think this will do what you want.
V = 1:9;
N = numel(V);
N1 = ceil(N/2);
h = hankel(V);
V1 = h(1:N1,1:N1)

추가 답변 (2개)

James Tursa
James Tursa 2011년 8월 6일

0 개 추천

Also not sure how general you want the method to be, but here is another way for your particular example:
n = ceil(numel(V)/2);
V1 = bsxfun(@plus,1:n,(0:n-1)');
Kyle
Kyle 2011년 8월 6일

0 개 추천

I have lots of historical data that I can sometime be up to 20,000 points. I want to covert this array to V1 array as described in my original post. The matrix could be X columns wide (X could be 10,20,40, or 100 columns). The ideal solution is I can specify X columns to get the desired matrix.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2011년 8월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by