Reduce Computing Time Part 2

Original Q:
"Hey I have somewhat tricky task of reducing computation time for one line of code in my professor's project. Is there any way to reduce the following code so that it computes at a faster rate (maybe 0.01s), right now the time to beat is 0.08s. The code is as follows:
(32 bit IEEE demultiplexed)
x = hex2float( dec2hex( fread(fid, 1, 'ubit32', 0, 'ieee-be') )) Basicslly looking for quicker way to convert the binary file to float. If you're not sure, I'm open to specifics suggestions. Also, would it be better if I wrote a code like this in C first and then let matlab read from there? Thank you."
I have tried this code:
x = fread(fid, 1, 'ubit32=>float32', 0, 'ieee-be')
and got this response back from prof;
"Dejan,
It doesn't work, function provides totally different number. For testing I would suggest to create input "number" (file, or just this 32 something variable in line). To do so I would try reverse, say take some double, convert it to float then, float2hex, then hex2dec. As a result I assume that you would have variable to play with and apply different solutions for x to covvert it back.
-Y"
Any suggestions based off this? I'm still somewhat confused. Again, can't test directly as I don't have Matlab at home.

7 Comments

UBIT32->double->hex->float is an extremly messy job. I'm stillconvinced that a direct conversion in 1 step is possible.
Without test data looking for a solution is guesswork and therefore it wastes your and out time. Please provide the necessary input and output values.
See: http://www.mathworks.com/matlabcentral/answers/36697-reducing-computation-time
Input would be like suggested, a 32 character of binary,
"00010001111000001000100010101000" and output should be a double precision floating point I believe.
Yes, looking for 1 step conversion if possible.
Can you please specify what, exactly, is in the file and what you are trying to convert it to? Do you have 32-bit floating point bit patterns in big endian IEEE format in the file? Do you have 32 1-byte character values of '0' and '1' that you are trying to string together into a floating point bit pattern? Or what? What is the machine you are reading it into, also a big endian IEEE machine, or little endian, or ??? Since the code you provided doesn't work properly according to your prof, we can't rely on it to determine what you are actually trying to do. Please be as explicit as possible with your description.
Again, from what I understand the original code works;
x = hex2float( dec2hex( fread(fid, 1, 'ubit32', 0, 'ieee-be') ))
so the input file is binary (32 1-byte values) that can be read with 'ubit32'. The machine ordering is big endian.
No, ubit32 reads 32 bits, not 32 1-byte values.

Sign in to comment.

Answers (1)

Should it just be
x = fread(fid, 1, 'ubit32=>double', 0, 'ieee-be')
would that solve the problem?

Categories

Tags

Asked:

on 30 Apr 2012

Community Treasure Hunt

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

Start Hunting!