0

我想在 matlab 中创建一个二进制数,并且很难连接这些数字。

这是我到目前为止所尝试的:

testarray = zeros(10,10)
testarray = num2str(testarray) % Convert all values to type string

testarray(1,1) = num2str(1); % Fill with abitrary value

testarray(1,1) = strcat(testarray(1,1), num2str(0)); % Trying to make '10' here but instead I get this error: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"

任何帮助,将不胜感激。

4

1 回答 1

1

在您的示例中,问题是'10'大小为 [1,2],但 testarray(1,1) 的大小为 [1,1]。因此,您可以考虑改用单元格:

testarray = cell(5,5);
testarray{1,1} = strcat(testarray(1,1), num2str(0)); 

顺便说一句,你应该看看函数dec2bin

从文档中:

dec2bin(23)
ans =
    10111

结果值是一个字符串

因此,如果您想连接两个二进制值(编码为字符串),只需执行以下操作:

['10' '11']
ans =
    1011
于 2013-11-04T01:46:37.237 回答