# reduce the working precision

1 view (last 30 days)
I have some 2 dimesional array (varaibles), like A(100, 100), B(100, 100). Matlab takes 16 decimal places for all calculations. But, I need to fix ONLY 6 decimal palces for all my calculations (numerical simulations). How do i fix all my varibales in my code with only 6 or 8 decimal places.

Steven Lord on 4 Jun 2021
Take a look at Fixed-Point Designer. It may do what you want.

Andy Bartlett on 7 Jun 2021
I'm guessing you want your simulation code to be smaller and faster.
Single precision floating-point provides around 7 decimal digits of accuracy and can achieve that goal.
Make sure the key entry points to your algorithm are single.
If the inputs are all singles, most of your calculations will be produce single precision results.
A = single( rand(3,2) );
B = single( rand(2,4) );
C = A * B
C =
3×4 single matrix
0.68457 0.23552 0.11531 1.2855
0.39312 0.13022 0.069436 0.83144
0.59251 0.20564 0.098654 1.0794
Converting a MATLAB m-file from double precision to single precision can be automated using convertToSingle.
If you have a Simulink subsystem in double precision that you wanted to convert to single, the conversion can also be automated.

### Community Treasure Hunt

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

Start Hunting!

Translated by