To speed up your code, first try profiling and vectorizing it. For information, see Performance and Memory (MATLAB).
After profiling and vectorizing, you can also try using your computer’s GPU to speed up your
calculations. If all the functions that you want to use are supported on the GPU, you can
gpuArray to transfer input data to the GPU, and call
gather to retrieve the output data from the GPU. To get started with GPU
computing, see Run MATLAB Functions on a GPU.
For deep learning, MATLAB® provides automatic parallel support for multiple GPUs. See Deep Learning with MATLAB on Multiple GPUs (Deep Learning Toolbox).