divide a vector into two vectors of unequal length

조회 수: 1 (최근 30일)
reta jon
reta jon 2021년 10월 1일
댓글: reta jon 2021년 10월 1일
How do I divide a vector into two vectors of unequal length so that the first vector contains 2/3 ,and the other contains1/3
Example
A=[1 2 3 4 5 6]
result
B=[ 1 2 3 4 ]
C=[6 7]
  댓글 수: 2
Jan
Jan 2021년 10월 1일
I assume you mean C = [5,6], because A does not contain a 7.
reta jon
reta jon 2021년 10월 1일
That's right, thank you, sir

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

채택된 답변

Jan
Jan 2021년 10월 1일
A = [1 2 3 4 5 6];
idx = ceil(numel(A) * 2 / 3);
B = A(1:idx)
B = 1×4
1 2 3 4
C = A(idx + 1:end)
C = 1×2
5 6

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by