How to convert a string into row vector?

15 ビュー (過去 30 日間)
Ammy
Ammy 2022 年 3 月 11 日
回答済み: Image Analyst 2022 年 3 月 11 日
a = 753;
b= dec2bin(a);
b= '1011110001'
How can I obtain b as a row vector [1 0 1 1 1 1 0 0 0 1]?

採用された回答

Image Analyst
Image Analyst 2022 年 3 月 11 日
Please note that the other answers will not include the leading zero if there is one.
You didn't specify if you want leading zero(s) if there are any. You can specify the number of bits in dec2bin if you want. For example this (dec2bin(a, 8)) is what you might do
a = 103;
b = dec2bin(a)-'0' % Does not include leading zeros for an 8 bit number
b = 1×7
1 1 0 0 1 1 1
c = dec2bin(a, 8)-'0' % Does include leading zeros for an 8 bit number
c = 1×8
0 1 1 0 0 1 1 1
Did you want leading zeros or not?

その他の回答 (1 件)

Arif Hoq
Arif Hoq 2022 年 3 月 11 日
try this:
a = 753;
b= dec2bin(a)
b = '1011110001'
% b= '1011110001'
format longG
output=str2double(b)
output =
1011110001
  3 件のコメント
Ammy
Ammy 2022 年 3 月 11 日
@Arif Hoq Thank you very much!
Arif Hoq
Arif Hoq 2022 年 3 月 11 日
my pleasure

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by