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

serialconf.m
%   /***********************************************************************
% 
% * Company: TATA ELXSI LIMITED
% 
% * File Name: serailconf.m
% 
% * Author : Nitin S
% 
% * Version : 0.0.1
% 
% * Description: This script generates walkprofile based on inputs from the excel sheet
% 
% * Date :2/08/2005
% 
% * Customer Bug No./ CMF No. : NA
% 
% * Brief description of the fix/enhancement: NA
% 
% ***********************************************************************/
clear all ;

% serobj = serial('COM7') ;           % Creating serial port object now its connected to COM7
% 
% %Set connection properties
% serobj.Baudrate = 115200;      % Set the baud rate at the specific value
% set(serobj, 'Parity', 'none') ;     % Set parity as none
% set(serobj, 'Databits', 8) ;        % set the number of data bits
% set(serobj, 'StopBits', 1) ;        % set number of stop bits as 1
% set(serobj, 'Terminator', 'CR') ; % set the terminator value to carriage return
% 
% set(serobj, 'InputBufferSize', 512) ;                 % Buffer for read operation, default it is 512
% 
% get(serobj) ;       
% 
% fopen(serobj) ;
% get(serobj, 'Status')                 % Gets the status of connection if 'open' connection was established


%For write operation
serobjw = serial('COM6') ;           % Creating serial port object now its connected to COM7

%Set connection properties
serobjw.Baudrate = 115200;      % Set the baud rate at the specific value
set(serobjw, 'Parity', 'none') ;     % Set parity as none
set(serobjw, 'Databits', 8) ;        % set the number of data bits
set(serobjw, 'StopBits', 1) ;        % set number of stop bits as 1
set(serobjw, 'Terminator', 'LF') ; % set the terminator value to newline

set(serobjw, 'OutputBufferSize', 512) ;               % Buffer for write operation, default it is 512

get(serobjw) ;       

fopen(serobjw) ;
get(serobjw, 'Status')                 % Gets the status of connection if 'open' connection was established

Contact us at files@mathworks.com