0

I want to create a binary number in matlab and am having difficulty concatenating the numbers.

Here's what I tried so far:

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"

Any help would be appreciated.

1 Answer 1

1

In your example, the problem is that '10' has size [1,2], but testarray(1,1) has size [1,1]. So you might consider using cells instead:

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

By the way, you should have a look at the function dec2bin.

From the documentation:

dec2bin(23)
ans =
    10111

The resulting value is a string.

So if you want to concatenate two binary values (encoded as strings), just do:

['10' '11']
ans =
    1011
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I just used the cell method and that worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.