Hi,
I understand that you are encountering out of memory error when executing MATLAB code.
- There is insufficient memory for your largest array
- There is insufficient memory for all data used in the script
The best way to handle out of memory errors is to rewrite the code.
You can start by debugging the code for any logical errors. For example, check if you accidently create huge arrays e.g., by rand(1e6) if rand(1, 1e6) was meant.
You may need to rethink the data structures being used in the program and how they are manipulated. For e.g., using single instead of double, inefficient usage of structs/cells, using sparse arrays as much as possible etc. Please see Strategies for Efficient Use of Memory - MATLAB & Simulink (mathworks.com) for more information.
If the issue persists, you are limited by the memory on the machine that you are using. You can adjust settings to increase the available memory for MATLAB as explained in Resolve "Out of Memory" Errors - MATLAB & Simulink (mathworks.com)