Splitting a row matrix to different rows
1 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!