how to interchange the elements of a vector/matrix?
Show older comments
hi
a,b,c,d all are 2x1 matrices.
i will run a for loop and with each loop the elements of matrix x will increase.
example-
for i=1, x=[a1]
for i=2, x=[a1 b1 b2]
for i=3, x=[a1 b1 b2 c1 c2 c3 c4]
for i=3 x=[a1 b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8]
now after i=2, i want to rearrange the matrix to look like
y=[b1 a1 b2].
after i=3, i want to rearrange the matrix to look like
y=[c1 b1 c2 a1 c3 b2 c4]
after i=4, i want to rearrange the matrix to look like
y= [d1 c1 d2 b1 d3 c2 d4 a1 d5 c3 d6 b2 d7 c4 d8].
please tell me how i can do this?
basically all the new elements will be placed in between the existing elements.
3 Comments
lokender Rawat
on 7 May 2018
It is quite easy to do that. But you have not specified how the data in a,b,c and d are present. Because to get the desired output in each iteration, the number of elements in:
'a' should be 1,
'b' should be 2,
'c' should be 4,
'd' should be 8.
Please specify the format of input data. How a,b,c and d are fed as input to the program? Are they all present in a matrix? Or individual vectors?
Muhammad Ridwanur Rahim
on 7 May 2018
Muhammad Ridwanur Rahim
on 7 May 2018
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!