フィルターのクリア

Concatinate the ith element of one matrix with the ith element of second matrix

1 回表示 (過去 30 日間)
ARN
ARN 2019 年 2 月 25 日
コメント済み: Jan 2019 年 4 月 29 日
I have two matrices and i want to concatinate the 1st element of fist matrix with the first element of second matrix and so on (i'th with i'th)
Below are the arbitrary matrices (can be bigger but with same dimensions)
a=[1 2 3 4 5 6];
b=[10 11 12 13 14 15];
How can i get the result matrix?
result=[1 10 2 11 3 12 4 13 5 14 6 15];

採用された回答

madhan ravi
madhan ravi 2019 年 2 月 25 日
編集済み: madhan ravi 2019 年 2 月 25 日
"Below are the arbitrary matrices (can be bigger but with same dimensions)"
result=reshape([a(:) b(:)].',1,[])
  2 件のコメント
Jan
Jan 2019 年 2 月 25 日
編集済み: Jan 2019 年 2 月 25 日
Or slightly easier:
reshape([a; b], 1, [])
madhan ravi
madhan ravi 2019 年 2 月 25 日
Thanks Jan!

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

その他の回答 (1 件)

Jan
Jan 2019 年 2 月 25 日
Alternative:
a = [1 2 3 4 5 6];
b = [10 11 12 13 14 15];
c = zeros(1, numel(a) + numel(b));
c(1:2:end) = a;
c(2:2:end) = b;
  1 件のコメント
Jan
Jan 2019 年 4 月 29 日
@ARN: I answer a question, if I find the time to do this and if I have some potentially useful ideas about the question. It is considered to be impolite to push others to answer questions. Imagine how much noise you would find in the forum, if anybody advertises his or her questions in the section for comments of other threads. So please don't do this.

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

カテゴリ

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

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by