- Edited
Here is one hint for sending real-time data to MATLAB:
https://www.mathworks.com/help/xpc/real-time-udp.html
Bela can do UDP. Create a UDP client or server on the Bela in an AuxiliaryTask. One example of simplest UDP client/server I found with Google -- lots of hits, so lots of information for doing UDP with C on Linux:
https://stackoverflow.com/questions/35568996/socket-programming-udp-client-server-in-c
(first response with simple basic client and server examples are a good place to start -- you could begin by sending a simple "hello" to a MATLAB program).
I have done some TCP/IP communication on Linux to poll a temperature sensor and I have done some UDP in Python. Both the Python and C looked very similar, so my limited experience says it is not going to be particularly hard to get messages out to a MATLAB program running as a server. From there you can hack until you get the formatting and timing right.
A Bela AuxiliaryTask example:
https://github.com/BelaPlatform/Bela/blob/master/examples/04-Audio/sample-streamer/render.cpp
In the samplestreamer example data is streamed from disk to the audio output, but easy enough to do something like the reverse where you fill a buffer with audio data in real-time then signal the Aux task to copy a chunk and write it to disk and/or to a server using UDP.
If you are receiving data in MATLAB over UDP could also use MATLAB to write the data to disk on the remote side.
For writing wav files look at examples for doing this with <sndfile.h> directly if you're having trouble with the datalogging functions for Bela.
Here's another example to consider -- a hack way of reading/writing wav without an external library. I am using it on my server to run a guitar effect on a wav file and then outputting the processed audio into a different wav file, triggered by a cgi script. It's terrible hackish code, but it works.
http://cackleberrypines.net/transmogrifox/src/cgi_chorus/csource/