How do I play and record audio at the same time?
I suspect that your problem is to do with having your speakers and microphone on different ALSA audio devices or subdevices.

You need to find the available sound cards for recording and playback on your system. The following commands will tell you this information :

aplay -l
arecord -l


You will need to define a default full duplex sound card using your choice of devices you see in the output to the above commands.

The way to define this full duplex card (made of two different soundcard devices) is to define it in your ~/.asoundrc file. This example shows you how to do that, however I will repeat it here.

The requirement is that you use plughw as your device name because the clocks on the two sound cards will drift and you will need resampling of some form. But you can play with this option.

So for example if you want to take input from a device on the first card (hw:0) and output to the second device on the second card (hw:1,1) then you would write the following in your ~/.asoundrc file :

pcm.!default {
    type asym
    playback.pcm "plughw:1,1"
    capture.pcm  "plughw:0"
}
ctl.!default {
        type hw
        card 1
}


Hopefully now Matlab sees a full duplex card as the default device and allows full duplex operation.