Splitting a row matrix to different rows

1 回表示 (過去 30 日間)
Sara
Sara 2021 年 10 月 7 日
コメント済み: Sara 2021 年 10 月 7 日
I have a Matrix as:
A = [1 3 2 4; 3 1 5 0 ];
and I would like to convert it to a matrix like this:
B=[ 1 3; 1 2; 1 4; 3 1; 3 5; 3 0]
I would appreciate any help.
  2 件のコメント
Jan
Jan 2021 年 10 月 7 日
You forgot to mention the method. There is an infinite number of algorithms to construct a matrix based on another matrix. In your case the number of elements grws from 8 to 12. The chance to guess correctly, what you are looking for, is very small.
Sara
Sara 2021 年 10 月 7 日
Hi Jan,
Despite that I couldn't explain what I want. Your proposed sloution is exactly what I need.
I appreciate it

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

採用された回答

Voss
Voss 2021 年 10 月 7 日
Here's one way, if I am interpreting your method correctly:
B = [repelem(A(:,1),size(A,2)-1) reshape(A(:,2:end).',[],1)];

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by