Download presentation
Presentation is loading. Please wait.
Published byMartina Fisher Modified over 9 years ago
1
Chapter 1 – Matlab Overview EGR1302
2
Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory & Workspace Windows
3
Desktop Default appearance Command window Communicates with MATLAB program Type commands Receive response to your commands Displays “>>” prompt MATLAB is ready to receive instructions User types command, presses “Enter” to execute “;” at end of command suppresses response Retains previous keystrokes Use “ ↑” key to scroll backward Use “↓” key to scroll forward Edit with “←”, “→”, “Backspace”, “Delete”
4
Desktop Default appearance Command History window Shows all previous keystrokes Copies previous command to Command window Left-click and drag to Command window Double-click to re-execute command
5
Desktop Default appearance Current Directory window Serves as file manager window Double-click on.m file to open Editor window Workspace window Lists variables created in Command window Double-click on variable name to open Array Editor window
6
Desktop Default appearance Row of menu names Each window type has its own menu bar Toolbar Shortcut buttons Current directory box Change to directory in which you save your files Provides path for Current Directory window
7
Variables A symbol used to contain a value Used to write mathematical expressions Variable naming convention Must begin with a letter Must contain < 32 characters Is case sensitive May contain letters, digits, & underscore Scalar variable - a single number Array variable - a collection of numbers Can be handled by MATLAB as a single variable
8
Variables Assigning values to variables Use “=“ as assignment operator Variable name on left-hand side is replaced by value generated by right-hand side Right-hand side must have computable value Array assignment “[]” contains numbers being assigned Commas separate elements in row Semi-colons separate rows
9
Variables Array assignment (cont) Special format for assigning row array with regularly spaced numbers Type first number, last number, with spacing in middle All numbers separated by colon “:”
10
Variables Array addressing Use just variable name in expressions Operation is performed on every element in the array IF matrix operation is “legal” Use variable name & array index in expressions Point to a particular element in the array Use if operation to be performed is not “legal” matrix operation
11
Variables MATLAB has predefined variables Avoid using names of predefined variables as variable names
12
Mathematical Expressions Order of precedence Highest order of precedence first Operators of equal precedence from left to right
13
Functions MATLAB mathematical functions Pair of parentheses after function name encloses function’s argument Can be part of mathematical expression
14
Functions Users can define functions MATLAB commands and functions for managing the work session
15
Plotting Graphics window Appears in Desktop when a plot is generated
16
Plotting Simple rectilinear plot Function plot(x,y) Generates a plot with x-values on the horizontal axis and y-values on the vertical axis Function xlabel(‘xxxx’) Places text within single quotes as label for horizontal axis Function ylabel(‘yyyy’) Places text within single quotes as label for vertical axis
17
Plotting Simple rectilinear plot (cont) Function title(‘text’) Places text at top of plot Overlay plots Include another set or sets of values in plot function
18
Script Files Program files saved with.m extension Use Editor window
19
Script Files Naming convention Same as for naming variables Not the same name as a variable or a MATLAB function Use exist(‘name’) function to verify that a prospective filename is not already in use
20
Script Files Comments “%” - Not executed by MATLAB Comments section – at beginning of program 1 st line - name of the program, keywords 2 nd line - date created and programmer’s name 3 rd line – description of program’s purpose Variable definitions Input Output Internal to program
21
Script Files Comments Additional comments throughout program Break program into sections. Describe purpose for calculations Programming in MATLAB Relational operators Used to make comparisons
22
Script Files Programming in MATLAB (cont) Conditional statements Allow decision-making if expression commands elseif expression commands else commands end
23
Script Files Programming in MATLAB (cont) Loops Repeated calculations For Number of passes is known ahead of time While Looping terminates when a condition is met for k=1:10 commands end while condition commands end
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.