将n x 1向量附加到n x 1个单元阵列

时间:2017-05-21 17:38:35

标签: matlab vector concatenation cell-array

我正试图将[1 2.2]追加到{'foo''ba'}并获取:

    'foo'    'ba'               
    1        2.200000

我快到了:

>> A = {'foo' 'ba'}

A =

  1×2 cell array

    'foo'    'ba'

>> b = [1 2.2]

b =

   1.000000000000000   2.200000000000000

>> [A;b]
Error using vertcat
Dimensions of matrices being concatenated are
not consistent.

>> [A;num2cell(b)]

ans =

  2×2 cell array

    'foo'    'ba'               
    [  1]    [2.200000000000000]

如何摆脱[]?

2 个答案:

答案 0 :(得分:0)

[A;num2cell(b)]是正确的实施方式。

您可以尝试

[A(1);b(1)]

ans = 

    'foo'
    [  1]

注意表示为[1]的向量b元素1是等价的。

答案 1 :(得分:0)

drwxr-xr-x   - striim1       striim1                0 2017-05-19 02:50 /user/striim1