Actually, My read serial code just do two things, which is read data to buffer, and tell the another thread that it is time to process data. Here is my code, hope can help you if you encounter the same problem.
function readSensorData(app, src, ~)
numBytes = src.NumBytesAvailable;
% tic
if numBytes > 0
newData = read(src, numBytes, 'uint8');
app.rawData = [app.rawData; newData'];
send(app.dataQueue,1)
end
end
Which app.rawData has Initialized in setup, and code send(app.dataQueue,1) is tell another thread processing data.