12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

x = 0:.1:2*pi;y = sin(x);plot(x,y)The first line uses the colon operator to generate a vector x <strong>of</strong> numbersrunning between 0 <strong>and</strong> 2π with increment 0.1. The second line calculatesthe sine <strong>of</strong> this array <strong>of</strong> numbers, <strong>and</strong> calls the result y. The third lineproduces a plot <strong>of</strong> y against x. Go ahead <strong>and</strong> produce the plot. Youshould get a separate window displaying this plot. We have done in threelines <strong>of</strong> matlab what it took us seven lines to do using the Fortranprogram above.2 Typing into <strong>MATLAB</strong>2.1 Comm<strong>and</strong> Line EditingIf you make a mistake when entering a matlab comm<strong>and</strong>, you do nothave to type the whole line again. The arrow keys can be used to savemuch typing:↑ ctrl-p Recall previous line↓ ctrl-n Recall next line← ctrl-b Move back one character→ ctrl-f Move forward one characterctrl-→ ctrl-r Move right one wordctrl-← ctrl-l Move left one wordhome ctrl-a Move to beginning <strong>of</strong> lineend ctrl-e Move to end <strong>of</strong> lineesc ctrl-u Clear linedel ctrl-d Delete character at cursorbackspace ctrl-h Delete character before cursorctrl-k Delete (kill) to end <strong>of</strong> lineIf you finish editing in the middle <strong>of</strong> a line, you do not have to put thecursor at the end <strong>of</strong> the line before pressing the return key; you can pressreturn when the cursor is anywhere on the comm<strong>and</strong> line.2.2 Smart RecallRepeated use <strong>of</strong> the ↑ key recalls earlier comm<strong>and</strong>s. If you type thefirst few characters <strong>of</strong> a previous comm<strong>and</strong> <strong>and</strong> then press the ↑ keyc○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!