Is there anyway to convert a number to binary without using dec2bin?
조회 수: 22 (최근 30일)
이전 댓글 표시
Dear everyone
I want to convert these values to binary without using dec2bin
why I do not want dec2bin because for each value the result will be 8 bits this maximize the numbers of values and I want these number 21 values no more no less
in the same way that im2bw work I did it but the result are all ones
Here are the values 77.152,128.35,136.04,191.57,222.5,241.67,254.83,272.7,251.13,286.17,310.83,305.48,303.8,301.91,318.85,365.8,350.72,301.91,220.91,145.37,94.304
Here are the values after applying dec2bin(The problem: the number of values is very huge and I want it 21 values like the Original values) 0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,1,1,1,0,1,0,0,0,0,0,0,1,1,0,1,0,1,0,0,0,1,0,1,1,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1,0,1,0,1,1,1,1,0,1,1,1,0,1,0,1,1,0,0,1,1,1,1,1,1,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,1,1,1,1,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,1,0,1,0,1,0,1,0,0,0,1,1,0,0,1,0,1,0,0,1,0,0,1,1,1,0,1,0,1,0,1,0
Here are the values after applying im2bw(The problem:all the values are ones and I do not want that )
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Please,give me answers?
댓글 수: 3
Eric
2015년 4월 6일
I haven't the slightest idea what you're trying to accomplish, but all im2bw does is threshold an image. If you're not supplying the second argument (level), the default value of 0.5 is used. For an input image that is floating point then all pixel values greater than 0.5 will be 1. That's why im2bw is giving you all ones. The output of im2bw is a logical array and clearly not appropriate for whatever it is you're trying to do.
답변 (2개)
Stephen23
2015년 4월 6일
편집: Stephen23
2015년 4월 7일
This is an ill-defined problem, unless you specify what encoding method you want to convert decimal fractions. MATLAB only has dec2bin which converts integer values only. This is a topic that has been discussed before on MATLAB Answers, and even some other forums:
Although it is important to note that the problem is ill-defined, because "There is no one right answer on how to represent a fractional number in binary" (quoted from Peter at the last link).
댓글 수: 0
Mahdiyar
2015년 4월 6일
Hi Ameligege
It is simple . you can use the function de2bi instead of dec2bi.
regards,
참고 항목
카테고리
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!