How can Write a function that combines two lists by alternatingly taking elements, e.g. [23,11,70], [1,2,3] → [23,1,11,2,70,3].
Afficher commentaires plus anciens
function C= concat(L1,L2) T=[L1(1),L2(1)]; for i=2:length(L1) T(end+1)=L1(i) T(end+1)=L2(i);
end
C=T;
end
Réponse acceptée
Plus de réponses (2)
KL
le 10 Nov 2017
No need to use a loop,
A = [1 2 3 4 5];
>> B = 10*A;
>> C = zeros(size([A B]));
>> C(1:2:end) = A;
>> C(2:2:end) = B;
>> C
C =
1 10 2 20 3 30 4 40 5 50
anas birrow
le 10 Nov 2017
0 votes
Catégories
En savoir plus sur Programming 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!