Matlab 将nx1向量附加到nx1单元数组
我试图将[12.2]附加到{'foo''ba'}并获得:Matlab 将nx1向量附加到nx1单元数组,matlab,vector,concatenation,cell-array,Matlab,Vector,Concatenation,Cell Array,我试图将[12.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
'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]
如何摆脱[]?[A;num2单元(b)]
是正确的实现
你可以试试看
[A(1);b(1)]
ans =
'foo'
[ 1]
请注意向量b元素1表示为[1],它们是等价的。您做得对。在Matlab中,
1
和[1]
是完全相同的(请使用isequal(1[1])
进行检查)
A = {'foo' 'ba'} ;
b = {'1' '2.2'} ;
[A ;b]
or
vertcat(A,b)