You cannot avoid the error in general.
It appears very often, when a function calls itself recursively without intention. In this forum you find a lot of examples, where functions to be integrated by ODE45 call the integrator instead of the other way around. So these are simply mistakes.
Recursive functions can be solved by non-recursive code also in every case. This is more efficient considering the stack size im Matlab. So a soultion would be to avoid recursion. But sometimes recursive code is such nice, that the programmer hesitates to re-organize the code. Then the maximum depth of recursion must be adjusted to the possible size of the problem. But as the message warns you already: If the stack size is exhausted, Matlab might not be able to display a message anymore and you can only see a silent crash. This is extremely annoying and horrible to debug.
Please post the relevant part of the code. Then we could decide if it is a programming error or an intentional recursion and a specific suggestion is possible.