how to convert a single row matrix into an n bit number

8 vues (au cours des 30 derniers jours)
Elin Das
Elin Das le 3 Juil 2021
I am given a numerical array, a = [0 0 1 0 1 0 1]. i have to transform it into n bit number, n = column number,
a = 0010101.
sprintf and other functions ignore the preceding zeros, which isn't helpful.

Réponses (1)

Image Analyst
Image Analyst le 3 Juil 2021
Try this:
a = [0 0 1 0 1 0 1]
str = sprintf('%d', a)
num = bin2dec(str)
a =
0 0 1 0 1 0 1
str =
'0010101'
num =
21

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by