How to convert das decimal number to binary code and directly write into matrix columns?

My Problem: Given is a vector filled with decimals. Accordingly, I would like to create a matrix by creating a for loop that gives me the binary code in a column for the respective decimal number 0-7. Number of decimals arent given
just like that:
D = [0 4 3 7 2 5 6 ...]
F = [0 1 0 1 0 1 1
0 0 1 1 1 0 1
0 0 1 1 0 1 0 ]
Thanks for your solutions. ;)

Answers (1)

D = [0 4 3 7 2 5 6 7]
D = 1×8
0 4 3 7 2 5 6 7
F = dec2bin(D) % dec2bin
F = 8×3 char array
'000' '100' '011' '111' '010' '101' '110' '111'
use dec2bin function

Categories

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

Products

Release

R2022b

Asked:

on 13 Dec 2022

Answered:

on 13 Dec 2022

Community Treasure Hunt

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

Start Hunting!