Main Content

Quantizing Data with quantizer Objects

You construct a quantizer object to specify the quantization parameters to use when you quantize data sets. You can use the quantize function to quantize data according to a quantizer object's specifications.

Once you quantize data with a quantizer object, its state values might change.

The following example shows

  • How you use quantize to quantize data

  • How quantization affects quantizer object states

  • How you reset quantizer object states to their default values using reset

  1. Construct an example data set and a quantizer object.

    format long g
    rng(0,'twister');
    x = rng(100);
    q = quantizer([16,14]);
  2. Retrieve the values of the maxlog and noverflows states.

    q.maxlog
    ans =
    
        -1.79769313486232e+308
    q.noverflows
    ans =
    
         0

    Note that maxlog is equal to -realmax, which indicates that the quantizer q is in a reset state.

  3. Quantize the data set according to the specifications of the quantizer object.

    y = quantize(q,x);
    Warning: 625 overflow(s) occurred in the fi quantize operation.
  4. Check the values of maxlog and noverflows.

    q.maxlog
    ans =
    
              1.99993896484375
    q.noverflows
    ans =
    
       625

    Note that the maximum logged value was taken after quantization, that is, q.maxlog == max(y).

  5. Reset the quantizer states and check them.

    reset(q)
    q.maxlog
    ans =
    
        -1.79769313486232e+308
    q.noverflows
    ans =
    
         0