how to interchange the elements of a vector/matrix?
Afficher commentaires plus anciens
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 commentaires
lokender Rawat
le 7 Mai 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
le 7 Mai 2018
Muhammad Ridwanur Rahim
le 7 Mai 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!