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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by