How can I compress data points using flushdata or changing to single precision to allow the process to speed up?

2 views (last 30 days)
Hi! I've got a program that collects data and is supposed to run for days, if not a week or so, collecting data continuously (once every 3). As it collects it, it also plots it. I run into trouble as the program goes on, however because I'm storing 48bits of memory every 3 seconds. My question becomes now, is there a way to force Matlab to use single precision when storing data (instead of 8 bits per readout, have it be 1 or 2)? Also if there's a way to predetermine how much data is displayed at one time. The plots are a large drain on the memory too, and so I've decided to only allow for a max of 10 hours of data to be displayed, clearing the earliest 2 hours each time it reaches 10 hours. Problem becomes, I can't flush the data without clearing the whole plot.
Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 19 Jan 2016
Edited: Walter Roberson on 19 Jan 2016
You can use single() on data to convert it to single precision, 32 bits per value. The more typical double() is 64 bits per value.
If you are using fwrite() then you can control the precision the data is written at using the "precision" argument, such as
fwrite(fid, MyBuffer, 'single')
MATLAB does not have an in-memory datatype that is less than 8 bits; even logical are at least 8 bits. However, if you are writing a number of values at the same time with fwrite() then you can specify a precision of 'bitN' or 'ubitN' where N is replaced by the number of bits to write, such as 'bit3' or 'ubit1' . The values that are all written in the same call will be packed into consecutive bits; if the total does not happen to be a multiple of 8 bits long then final byte emitted will be padded with 0's.
  1 Comment
Rodmehr Semnani
Rodmehr Semnani on 21 Jan 2016
unfortunately, this doesn't solve the problem completely. I'll still have too much information, even if I scale down my data points. However, I believe I found a way to go around it: preallocating a cell array to hold my data as I go through the program.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!