fill a matrix with binary code in a for loop

3 views (last 30 days)
in a for-loop I get 30 times 3 bits each. To display the bits in a vector is no problem for me. But I would like to have a matrix after the 30 passes. Unfortunately my approach does not succeed.
for i = 1:30
% I reveive:
bit1 = [0]
bit2 = [1]
bit3 = [1]
% create Vektor works fine:
bitcode = [bit1 bit2 bit3]
% create Matrix doesnt work:
bitcode(i, :) = [bit1 bit2 bit3]
% neither that way:
for k = 1:length(bitcode)
bitcode(i,k) = bit(k)
Result should look like:
bitcode = [0 1 1; 1 1 1; 1 0 1]
I guess I'm doing something wrong?
David Fletcher
David Fletcher on 10 May 2021
Ok, I'll post it as an answer if it helped you, but it's not a big deal to me

Sign in to comment.

Accepted Answer

David Fletcher
David Fletcher on 10 May 2021
code = [0 1 1]
for k = 1:length(bitcode)
bitcode(k,:) = code

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by