As a first step, you can run the Measure Audio Latency example to verify that your audio I/O system is configured correctly:
For profiling your code:
You can also go through the following link that has several steps to troubleshoot the issue of signal dropping and latency
As far as what we observe, under/overruns sometimes happen the first time we run, but usually we're good every other execution because all the underlying code is now cached in memory.
If none of the above links helps, then we need to inspect if the issue is due to hardware limitation of the device being used or the system being used.
This results when the processing loop in MATLAB is not able to supply samples at the rate the sound card demands due to system hardware limitation.
Although we cannot guarantee a processing speed to achieve the task, we would like to suggest you setting up some profiling of your algorithm or try reducing sample rate which might give better results.
There might be another possible issue that Some devices have a control panel to set the buffer length, it should match what is being used in the code. Hence if latency is not an issue , try increasing buffer length.