from Guide to Serial Port Interfacing by Nitin Skandan
This article will give a detailed description of serial port interfacing in MATLAB.

serwritescript.m
%   /***********************************************************************
% 
% * Company: TATA ELXSI LIMITED
% 
% * File Name: serwritescript.m
% 
% * Author : Nitin S
% 
% * Version : 0.0.1
% 
% * Description: This script performs the serial write operation using a serial object already connected 
% 
% * Date :9/08/2005
% 
% * Customer Bug No./ CMF No. : NA
% 
% * Brief description of the fix/enhancement: NA
% 
% ***********************************************************************/

%Synchornous write operation
serobjw ;                                                             % Is the serobj which is already available
set(serobjw, 'Timeout', 1) ;                                  % Specify timeout for write operation


serobjw.BytesToOutput                                        % Shows the number of bytes in output buffer

fprintf(serobjw, 'How are you babe\n') ;              % write to the device
serobjw.ValuesSent                                             % Shows the number of values sent     
serobjw.BytesToOutput                                        % Shows the number of bytes in output buffer

fprintf(serobjw, 'I am fine dear\n') ;                     % write to the device
serobjw.ValuesSent                                             % Shows the number of values sent     

%Asynchornous write operation
fprintf(serobjw, 'How are you honey \n', 'async') ;              % write to the device
serobjw.BytesToOutput                                                      % Shows the number of bytes in output buffer

Contact us at files@mathworks.com