Simple rearrangement of matrix

1 次查看(过去 30 天)
I want to rearrange a vector A= [1,2,3]' to a vector B=[1,1,2,2,3,3]
Here is what i tried so far:
A = [1,2,3]';
for i = 1:size(A,1)
B(i,:)=[A(i) ; A(i)];
end
B=B
Which outputs a not quite right answer...:
B =
1 1
2 2
3 3
Any help is aprriciated..
Jens

采纳的回答

Sriram Tadavarty
Sriram Tadavarty 2020-4-4
Hi Jens,
Small modification to what you have done would work, this doesn't require a for loop
A = [1,2,3]';
B = [A A];
B = reshape(B',1,[]);
Hope this helps.
Regards,
Sriram
  2 个评论
Sriram Tadavarty
Sriram Tadavarty 2020-4-5
Hi Jens,
Please do accept the answer, if helped.
Regards,
Sriram

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by