How to take alternating elements from two vectors?
Mostrar comentarios más antiguos
I am very new to Matlab
a1 = [1 2 3 4 5 6 7]
a2 = [11 22 33 44 55 66 77]
i need a3 to be
a3 = [1 22 3 44 5 66 7]
how do i get a3?
Respuestas (2)
Simpler:
>> a3 = a1;
>> a3(2:2:end) = a2(2:2:end)
a3 =
1 22 3 44 5 66 7
KSSV
el 24 de Abr. de 2018
a1 = [1 2 3 4 5 6 7]
a2 = [11 22 33 44 55 66 77]
% i need a3 to be
a3 = [1 22 3 44 5 66 7]
iwant = zeros(size(a1)) ;
iwant(1:2:end) = a1(1:2:end) ;
iwant(2:2:end) = a2(2:2:end) ;
Categorías
Más información sobre Operating on Diagonal Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!