converting floating numbers to binary and set the result in a matrix form
8 views (last 30 days)
Show older comments
Hi,
Lets suppose we have a simple matrix x = [6.01179008584765e-08 6.45966692516766e-08 1.34123895886390e-07 ; 6.01179008584670e-08 6.45966692516663e-08 1.34123895886373e-07]
Question 1: I want to convert each floating number to binary and set the value of each in a matrix so the result should look like this:
x1=[1st binary value 2ed binary value ; 3ed binary value 4th binary value] >> in matrix form
*Notice the semicolon separating the first row and the second row
Question 2: should I convert the numbers to decimal first than to binary? if so, is there a function to convert floating point numbers to decimal? (built in function?)
3 Comments
Image Analyst
on 31 Jan 2015
I don't have float2bin() - it's not a function in base MATLAB or any of my toolboxes so I can't help you with that. I asked 3 questions (homework, data type, and difference) and you didn't answer a single one. So good luck with this. Someone else will probably guess what you mean, and attempt an answer, but I don't know what to do.
Accepted Answer
Guillaume
on 31 Jan 2015
I don't know how your float2bin works, but I assume it uses typecast to change the numbers from double to uint64 without modifying the underlying bit representation. typecast can indeed only deal with vectors. Once data is uint64, you can just use dec2bin to get the binary representation as string. It is trivial to reshape your output with reshape:
x = [6.01179008584765e-08 6.45966692516766e-08 1.34123895886390e-07
6.01179008584670e-08 6.45966692516663e-08 1.34123895886373e-07];
b = dec2bin(typecast(x(:), 'uint64'), 64);
b = reshape(num2cell(b, 2), size(x))
It all seems a bit pointless though. Why do you care about the binary representation of doubles?
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!