As per my understanding, you are trying to fully utilize all CPU logical processors for faster execution of the program.
To resolve this issue, you can leverage ‘Parallel Computing Toolbox’ that accelerates workflow using multicore processors where ‘Parallel for-Loops’ (Section 2) can help execute loops parallelly. Also ‘Profiling’ is helpful to investigate parts of code where the most time is spent.