fill a matrix with binary code in a for loop

조회 수: 1 (최근 30일)
Christian
Christian 2021년 5월 9일
답변: David Fletcher 2021년 5월 10일
Hi,
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)
end
end
Result should look like:
bitcode = [0 1 1; 1 1 1; 1 0 1]
I guess I'm doing something wrong?
  댓글 수: 3
Christian
Christian 2021년 5월 10일
편집: Christian 2021년 5월 10일
thank you! you are absolutely right. logic is sometimes not very strong with me. your solution works, thank you very much!:)
(@David Fletcher: I would like to confirm your statement as an answer, unfortunately I can't do that since you used the comment function)
David Fletcher
David Fletcher 2021년 5월 10일
Ok, I'll post it as an answer if it helped you, but it's not a big deal to me

댓글을 달려면 로그인하십시오.

채택된 답변

David Fletcher
David Fletcher 2021년 5월 10일
code = [0 1 1]
for k = 1:length(bitcode)
bitcode(k,:) = code
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by