Combine two vectors together

3 ビュー (過去 30 日間)
HAIRU WANG
HAIRU WANG 2020 年 4 月 20 日
回答済み: Bruno Luong 2020 年 8 月 28 日
For example I got a = [1 3 5], b = [2 4] and I want to get a c = [1 2 3 4 5 ]
Basically it'd insert the vaule from b between a's two elements

回答 (3 件)

KSSV
KSSV 2020 年 4 月 20 日
iwant = sort([a, b])

Bruno Luong
Bruno Luong 2020 年 8 月 28 日
a(1:2:2*end-1) = a;
a(2*(1:length(b))) = b

Osip Vayner
Osip Vayner 2020 年 8 月 28 日
KSSV's code is correct.
And just in case you want to combine two vectors vertically:
d = sort([a;b])

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by