Is there a way to get an 8 x 1 matrix instead of 8 x 3 using dec2bin or any other?
조회 수: 8 (최근 30일)
이전 댓글 표시
dec2bin (2 ^ n-1: -1: 0) - '0'
댓글 수: 2
Image Analyst
2021년 2월 27일
편집: Image Analyst
2021년 2월 27일
Give an example using some specific value of n and show what you got and what you want to get.
채택된 답변
Walter Roberson
2021년 2월 27일
string(dec2bin (2 ^ n-1: -1: 0))
This will be considered an array. The entries will be string objects such as "011". The entries will not be numeric.
댓글 수: 1
Walter Roberson
2021년 2월 27일
Perhaps you want
n=3
b = (dec2bin (2 ^ n-1: -1: 0) - '0')*10.^(n-1:-1:0).'
Note that if you do this, then the only way to get the leading zeros is to format it as text again.
추가 답변 (1개)
참고 항목
카테고리
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!