User:Eml4500.f08.bottle.barnes/HW1

Command Line Editing and Recall
The left and right arrow keys can be used to move the cursor and the Backspace key can be used to delete a character. On a PC, hitting the Home key will position the cursor at the beginning of the command line, while the End key will position it at the end of the line.

The up and down arrow keys can be used to move through previous commands. A previous command can be recalled, edited and executed over again. For example, typing

a=rand(8)

in the command line yields:

a =

0.8909   0.8143    0.3517    0.3804    0.5688    0.1656    0.2290    0.1067    0.9593    0.2435    0.8308    0.5678    0.4694    0.6020    0.9133    0.9619    0.5472    0.9293    0.5853    0.0759    0.0119    0.2630    0.1524    0.0046    0.1386    0.3500    0.5497    0.0540    0.3371    0.6541    0.8258    0.7749    0.1493    0.1966    0.9172    0.5308    0.1622    0.6892    0.5383    0.8173    0.2575    0.2511    0.2858    0.7792    0.7943    0.7482    0.9961    0.8687    0.8407    0.6160    0.7572    0.9340    0.3112    0.4505    0.0782    0.0844    0.2543    0.4733    0.7537    0.1299    0.5285    0.0838    0.4427    0.3998

Rather than having to move between MATLAB and the editor, the line can be directly recalled yielding a new set of random numbers:

a =

0.2599   0.8693    0.4018    0.9027    0.7803    0.5752    0.6491    0.6868    0.8001    0.5797    0.0760    0.9448    0.3897    0.0598    0.7317    0.1835    0.4314    0.5499    0.2399    0.4909    0.2417    0.2348    0.6477    0.3685    0.9106    0.1450    0.1233    0.4893    0.4039    0.3532    0.4509    0.6256    0.1818    0.8530    0.1839    0.3377    0.0965    0.8212    0.5470    0.7802    0.2638    0.6221    0.2400    0.9001    0.1320    0.0154    0.2963    0.0811    0.1455    0.3510    0.4173    0.3692    0.9421    0.0430    0.7447    0.9294    0.1361    0.5132    0.0497    0.1112    0.9561    0.1690    0.1890    0.7757

Submatrices and Colon Notation
Using “Colon notation” in MATLAB allows for both the generation of vectors and the referencing of submatrices. This along with subscripting by integral vectors are tools that allow the user to cut down on the use of loops, which slows the program and makes it harder to read.

For example, typing in something as simple as:

x=[0.0:0.2:4.0]'; y=sin(x); [x y]

produces a table of sines:

ans =

0        0    0.2000    0.1987    0.4000    0.3894    0.6000    0.5646    0.8000    0.7174    1.0000    0.8415    1.2000    0.9320    1.4000    0.9854    1.6000    0.9996    1.8000    0.9738    2.0000    0.9093    2.2000    0.8085    2.4000    0.6755    2.6000    0.5155    2.8000    0.3350    3.0000    0.1411    3.2000   -0.0584    3.4000   -0.2555    3.6000   -0.4425    3.8000   -0.6119    4.0000   -0.7568

To access particular submatrices of a matrix, colon notation can be used as follows:

x(1:3,1)

produces the first three entries in the first column:

ans =

0   0.2000    0.4000

A single colon refers to an entire row or column: x(:,2) refers to the second column of x, for example.

Integral vectors such as: x(:,[1 2]) includes columns 1 and 2 of x as subcripts.

To replace columns of a matrix, typing: x(:, [1 2]) = B(:,1:2) overwrites the first and second column of x with the first and 	second column of B producing:

x =

0.4868   0.2305    0.4359    0.8443    0.4468    0.1948    0.3063    0.2259    0.5085    0.1707    0.5108    0.2277    0.8176    0.4357    0.7948    0.3111    0.6443    0.9234    0.3786    0.4302    0.8116    0.1848    0.5328    0.9049    0.3507    0.9797    0.9390    0.4389    0.8759    0.1111    0.5502    0.2581    0.6225    0.4087    0.5870    0.5949    0.2077    0.2622    0.3012    0.6028    0.4709    0.7112

When x is and n-vector typing:

x=x(n:-1:1)

produces:

x =

0.4468   0.4359    0.4868

Entering:

y=fliplr(x) and y=flipud(x’)

yields:

y =

0.4868   0.4359    0.4468

and y=flipud(x) flips the matrix vertically.