Need to combine every other column of two row vectors of different sizes in MATLAB

3 visualizaciones (últimos 30 días)
I have 2 row vectors of different sizes, say:
A = [1 3 5 7 9 11 13 15 17]
B = [2 4 6 8 10 12].
I need to combine vectos A & B to make a new C vector that is the same length of the shorter matrix B such that,
C = [ 1 2 3 4 5 6].
Any help would be very much appreciated, I can't seem to figure out the proper indexing needed to accomplish this in a for loop.

Respuesta aceptada

Star Strider
Star Strider el 22 de Mzo. de 2019
Editada: Star Strider el 22 de Mzo. de 2019
One approach:
A = [1 3 5 7 9 11 13 15 17];
B = [2 4 6 8 10 12];
C(1:2:numel(A)*2) = A;
C(2:2:numel(B)*2) = B;
C = C(1:min(numel(A),numel(B)))
producing:
C =
1 2 3 4 5 6

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by