Combine two vectors together

For example I got a = [1 3 5], b = [2 4] and I want to get a c = [1 2 3 4 5 ]
Basically it'd insert the vaule from b between a's two elements

Respuestas (3)

Bruno Luong
Bruno Luong el 28 de Ag. de 2020
a(1:2:2*end-1) = a;
a(2*(1:length(b))) = b
Osip Vayner
Osip Vayner el 28 de Ag. de 2020

0 votos

KSSV's code is correct.
And just in case you want to combine two vectors vertically:
d = sort([a;b])

Categorías

Productos

Preguntada:

el 20 de Abr. de 2020

Respondida:

el 28 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by