MATLAB: 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].

alternatingly combines

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

Best Answer

Using the reshape function:
A = [23,11,70];
B = [1,2,3];
Out = reshape([A; B], 1, [])
Out =
23 1 11 2 70 3