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

8 ビュー (過去 30 日間)
Elin Das
Elin Das 2021 年 7 月 3 日
回答済み: Image Analyst 2021 年 7 月 3 日
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.

回答 (1 件)

Image Analyst
Image Analyst 2021 年 7 月 3 日
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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by