필터 지우기
필터 지우기

extract vector from large vector

조회 수: 9 (최근 30일)
Chaudhary P Patel
Chaudhary P Patel 2022년 4월 6일
댓글: DGM 2022년 4월 6일
i have vector [0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ]
from this i have to extract 5 vectors which are;
[0 0 0 1 2 3]
[1 2 3 4 5 6]
[4 5 6 7 8 9]
[7 8 9 10 11 12]
[10 11 12 13 14 15]
how can write code for this.

답변 (1개)

DGM
DGM 2022년 4월 6일
Instead of generating a bunch of loose vectors, it's often better to just use a matrix:
A = [0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];
B = repelem(reshape(A,3,[]),1,2);
B = reshape(B(:,2:end-1),6,[]).'
B = 5×6
0 0 0 1 2 3 1 2 3 4 5 6 4 5 6 7 8 9 7 8 9 10 11 12 10 11 12 13 14 15
  댓글 수: 2
Chaudhary P Patel
Chaudhary P Patel 2022년 4월 6일
sir i dont want as a matrix of 5X6. i want a vector of 6X1.
DGM
DGM 2022년 4월 6일
Well then I guess you can make a bunch of vectors then.
A = [0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];
myfirst6x1vector = A(1:6)
mysecond6x1vector = A(4:9)
mythird6x1vector = A(7:12)
myfourth6x1vector = A(10:15)
myfifth6x1vector = A(13:18)
...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by