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

 采纳的回答

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

2 个评论

thanks for ur help but i need this code in function to calling it
I am not certain what you are asking.
See if this does what you want:
function C = concat(L1,L2)
C = reshape([L1; L2], 1, [])
end
or using an anonymous function:
concat = @(L1,L2) reshape([L1; L2], 1, []);

请先登录,再进行评论。

更多回答(2 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by