Is there a way to get an 8 x 1 matrix instead of 8 x 3 using dec2bin or any other?
2 次查看(过去 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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!