Problem with MATLAB to Arduino MEGA

I get round this by getting matlab to check the connection status first:

Comtest = arduino.TransferStatus; % check port status before trying to write
if Comtest(1) == 'i';
fwrite(arduino, ServoValue, 'uint8','async')
else
Comtest;
pause(0.08)
end

Hope this helps