How to convert a string into row vector?
조회 수: 15 (최근 30일)
이전 댓글 표시
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]?
댓글 수: 0
채택된 답변
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
c = dec2bin(a, 8)-'0' % Does include leading zeros for an 8 bit number
Did you want leading zeros or not?
댓글 수: 0
추가 답변 (1개)
Arif Hoq
2022년 3월 11일
try this:
a = 753;
b= dec2bin(a)
% b= '1011110001'
format longG
output=str2double(b)
댓글 수: 3
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!