我有一个7395X28数值的matlab单元格,我有一个7395x8的另一个字符单元格,其中有二进制值。我希望二进制值单元格合并到这个数值单元格而不做任何更改。
例如,让数字单元格为A,二进制单元格B i将它们合并为
C = [A,B]
这给了我一个错误,说你不能将字符单元格与数值单元格合并。请任何人帮我解决这个问题
输出应该是合并的单元格,单元格的最后一列应该包含二进制值。请帮忙。
答案 0 :(得分:0)
<强>代码强>
a1 = num2cell(randi(5,2,3)) %%// cell array of numerical values
a2 = {'0' '1' '1'; '0' '1' '0' } %%// cell array of characters that are binary numbers
out = num2cell(cell2mat(a1)*10+cell2mat(a2)-'0')
<强>输出强>
a1 =
[4] [3] [5]
[2] [4] [5]
a2 =
'0' '1' '1'
'0' '1' '0'
out =
[40] [31] [51]
[20] [41] [50]
修改1:
<强>代码强>
A={1,2,3;
2,3,4;
4,5,6;
7,8,9;
0,9,9}
B={'0001'; '0011'; '0111' ;'1111' ;'0101'}
C = [A cellstr(cell2mat(B))]
<强>输出强>
C =
[1] [2] [3] '0001'
[2] [3] [4] '0011'
[4] [5] [6] '0111'
[7] [8] [9] '1111'
[0] [9] [9] '0101'
编辑2:
<强>代码强>
A={1,2,3;
2,3,4;
4,5,6;
7,8,9;
0,9,9}
B = ['00000001';'00010001';'00000001';'10110001';'01010011']
C = [A cellstr(B)]
<强>输出强>
C =
[1] [2] [3] '00000001'
[2] [3] [4] '00010001'
[4] [5] [6] '00000001'
[7] [8] [9] '10110001'
[0] [9] [9] '01010011'