Is there anyway to convert a number to binary without using dec2bin?

조회 수: 18 (최근 30일)
Ameligege
Ameligege 2015년 4월 6일
편집: Stephen23 2015년 4월 7일
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
Ameligege
Ameligege 2015년 4월 6일
I am looking for result like im2bw .This mean for each number represented by 0 or 1 not only one . Is there any way to do that or not?
Eric
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
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).

Mahdiyar
Mahdiyar 2015년 4월 6일
Hi Ameligege
It is simple . you can use the function de2bi instead of dec2bi.
regards,
  댓글 수: 1
Ameligege
Ameligege 2015년 4월 6일
An error occur when I test it on single value
de2bi(77.125)
Error using de2bi (line 127) Input must contain only finite real nonnegative integers.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by