Friday, May 6, 2011

Matrices of String Input

Enter MATLAB strings surrounded by single quotes ('string').



Strings are stored as character arrays, one ASCII character per element. Thus, the date string

DateString = '9/16/2001'


is actually a 1-by-9 vector. Strings making up the rows of a matrix or vector all must have the same length. To enter several date strings, therefore, use a column vector and be sure all strings are the same length. Fill in with spaces or zeros. For example, to create a vector of dates corresponding to irregular cash flows

DateFields = ['01/12/2001'
'02/14/2001'
'03/03/2001'
'06/14/2001'
'12/01/2001'];


DateFields actually becomes a 5-by-10 character array.



Don't mix numbers and strings in a matrix. If you do, MATLAB treats all entries as characters. For example,

Item = [83  90  99 '14-Sep-1999']


becomes a 1-by-14 character array, not a 1-by-4 vector, and it contains

Item =

SZc14-Sep-1999
http://www.mathworks.com/help/toolbox/finance/f2-1000003.html

1 comment:

  1. George, your post is not clear... no label and no explanation.

    ReplyDelete