How to Add Values from One Matrix in between the values of another?

1 回表示 (過去 30 日間)
Ibro Tutic
Ibro Tutic 2017 年 8 月 2 日
コメント済み: Star Strider 2017 年 8 月 2 日
Let's say you have a matrix a=[ 1 3 5 7 9 11] and b = [ 2 4 6 8 10]. How would you go about merging the two matricies so that every value of b goes in between the values of a? So the result would look like c = [ 1 2 3 4 5 6 7 8 9 10 11]. These can be any number, not specific to even/odd.

採用された回答

Star Strider
Star Strider 2017 年 8 月 2 日
This works:
a = [ 1 3 5 7 9 11];
b = [ 2 4 6 8 10];
c = zeros(1, numel(a)+numel(b));
c(1:2:end) = a;
c(2:2:end) = b;
c =
1 2 3 4 5 6 7 8 9 10 11
  2 件のコメント
Ibro Tutic
Ibro Tutic 2017 年 8 月 2 日
Perfect, thank you.
Star Strider
Star Strider 2017 年 8 月 2 日
My pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by