Question

I'm just curious to know if I can reduce memory usage of Matlab by using some option. Clicking on a variable in workspace shows a long digit which may not be necessary in most of cases. e.g.,

[20, 25.0540913632159, 16.2750000000000, 3.08852992798468];

for me 25.054091 may be more than ok. Are there any options that Matlab just reduce numbers for internal calculation and does it make any difference.

Was it helpful?

Solution

Modern PC's use floating point numbers to calculate non-integral values.

These come in two standardized variants: float and double, where the latter is twice the size of the former.

Matlab, by default uses (complex) doubles for all its calculations.

You can force it to use float (or as Matlab calls them, single) by specifiying the type:

a = single([20, 25.0540913632159, 16.2750000000000, 3.08852992798468]);

This should use half the memory, and you lose some precision that may or may not be important in your application. Make sure the optimization is worth it before doing this, as execution speed may even be slower (due to builtin functions only operating on double, hence requiring two conversions extra).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top