是否有一个功能"拉链"两种细胞阵列在一起吗? [英] Is there a function to "zip" two cell arrays together?

查看:165
本文介绍了是否有一个功能"拉链"两种细胞阵列在一起吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个单元阵列 A B ,像这样:

Suppose I have a cell array A and B, as so:

A = {'A' 'B' 'C' 'D'};
B = {1 2 3 4 };

我想通过荏苒A和B一起创建单元阵列 C ,像这样:

C = zip(A,B)
C = 
    'A' 1 'B' 2 'C' 3 'D' 4

有没有这样的功能存在吗? (显然,这样的功能并不难写,但懒惰是程序员最好的朋友,如果这样的功能已经存在,我宁愿使用。)

Does such a function exist? (Obviously such a function would not be difficult to write, but laziness is a programmer's best friend and if such a function already exists I'd rather use that.)

(我从Perl中,其中的 列表:: MoreUtils 包提供了拉链函数做到这一点。这个名字来源于一个事实该拉链函数交错两个列表,像拉链一样)。

(I got the idea from Perl, where the List::MoreUtils package offers the zip function that does this. The name comes from the fact that the zip function interleaves two lists, like a zipper.)

推荐答案

这个怎么样:

C = [A(:),B(:)].';   %'
D = C(:)

返回:

D = 

'A'
[1]
'B'
[2]
'C'
[3]
'D'
[4]

这篇关于是否有一个功能"拉链"两种细胞阵列在一起吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆