MatlabTutorial

MatlabTutorial - Outline The Matlab environment Variables...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Matlab Tutorial September 25, 2007 Outline • The Matlab environment • Variables • Arrays • Scripts and functions • Plotting The Matlab Environment Command Window Command Prompt Workspace myVar = 42; >> Current Directory Path Remember… … make sure you have the correct path!
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variables • A container with a name that we can read – Stores numbers, arrays, text, etc. •Examp les >> myNum = 31.2; >> my_Vec1 = [21, 22, 43]; >> some_text = ‘hello, world!’; Variable name (optional) If omitted, Matlab stores the result in ‘ans’ Assignment Expression Semi-colon If omitted, Matlab echos the result Naming Variables • Must start with a letter –[a-z], [A-Z] • Can contain letters, numbers or an underscore • Should not be the same as a Matlab reserved word – Function name (sin, cos, log10, plot, …) – Special numbers (i = sqrt(-1), pi) Clearing Variables • Use the ‘clear’ command – Clear ALL variables >> clear; – Clear a certain variable >> clear myNum; Arrays • Array: an ordered set of numbers – 1D: vector –2D: matr ix •Syn tax >> myMatrix = [1, 2, 3; 4, 5, 6; 7, 8, 9]; • You can enter an array in a spreadsheet –In Mat
Background image of page 2
Editing Arrays in Matlab Create a blank array >> myDataRecord = []; Select the variable in your workspace, and click “Open selection” Enter your data Importing arrays from Excel 1. Using the ‘Import Data’ wizard Open the File menu and choose Import Data 2. Copy and Paste Create a blank array in Matlab Open the array in the Array Editor Copy from the Excel spreadsheet into Matlab Working with Arrays
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

MatlabTutorial - Outline The Matlab environment Variables...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online