User:Eml4500.f08.echo.sell.cm/HW1

How to Create a Matrix
The following are ways to assign data to matrices in MATLAB: i.e. entering "A = [1 1 1; 2 2 2; 3 3 3]" or entering " A = [             1 1 1             2 2 2             3 3 3 ]" into MATLAB are both proper ways to create a matrix named A where each row contains three number "1's", "2's" and "3's" respectively and each column contains the numbers 1 through 3.
 * Data is entered through an explicit list of elements

Users may also enter/change a specific data point by entering the matrix name followed by (row, column) i.e. If we wanted to modify matrix A from above so that the data in row 1 column 3 (the top right hand corner) to contain the number 4, we would enter "A(1,3) = 4;"

i.e. MATLAB function "rand(m,n)" creates a matrix size m x n, where the data is randomly generated numbers uniformly distributed between the numbers 0 and 1 MATLAB function "magic(n)" creates a matrix size n x n, where the data is a magic square(rows, columns, and diagonals have a common sum) MATLAB function "eye(n)" creates an identity matrix size of n x n
 * Data is generated by-built in MATLAB statements and functions
 * Data is loaded into a matrix using a diskfile (.m file)
 * Data is loaded into a matrix using and external data file

Strings
In MATLAB a string is stored in a single row matrix with a separate column for each character in the string. Strings are entered into MATLAB by simply surrounding your string of characters with apostrophes as shown below.

>> strFirst = 'This is String 1';

So the words "This is String 1" is now stored in matrix "strFirst".

If one needs to determine the number of characters in a string, for example strFirst, simply type in the following:

>> size(strFirst)

And MATLAB should return:

ans = 1  16

You can also turn a string of characters into their corresponding ascii codes using the double command and turn a single row in a matrix to it's ascii character equivalent. The following is an example of how to convert strFirst to its ascii code and then back to a string.

Enter: >> strSec = double(strFirst)

Returns: strSec = 84  104   105   115    32   105   115    32    83   116   114   105   110   103    32    49

Enter: >> strThir = char(strSec)

Returns: strThir = This is String 1

One final note on strings, if there is ever a need for an apostrophe in a string use 2 sing apostrophes at the space where it's needed.