Reducing Computation Time
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 26 de Abr. de 2012
Is there a reason you are not just using
x = fread(fid, 1, '*float32', 0, 'ieee-be')
Also if you are doing a lot of calculations, it is almost always faster to use fread() to read a number of items at once. (If you stick with going through hex, then dec2hex() can be used on arrays.)
6 comentarios
Dejan Cvijanovic
el 26 de Abr. de 2012
Walter Roberson
el 27 de Abr. de 2012
Multiple binary formats should not affect my suggestion for reading a single 32 bit float.
Dejan Cvijanovic
el 27 de Abr. de 2012
Walter Roberson
el 27 de Abr. de 2012
The only way to know for sure is to try it.
I do not have access to MATLAB from home to experiment with. And even if I said that it worked, you would need to try it to be *certain*.
Dejan Cvijanovic
el 30 de Abr. de 2012
Jan
el 30 de Abr. de 2012
'ubit32' is very inefficient, when it really splits the reading to 32 bits. 'uint32' reads and processes them in a block.
Dejan Cvijanovic
el 26 de Abr. de 2012
0 votos
1 comentario
Jan
el 30 de Abr. de 2012
I'm sure *you* can confirm them. Simply compare the results and to be sure try it with a bunch of random numbers or bit-patterns.
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!