Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.

Similar presentations


Presentation on theme: "Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All."— Presentation transcript:

1 Introduction to MATLAB ENGR 1181 MATLAB 1

2 Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All programs/MATLAB  The following prompt should appear in the command window: >>

3 MATLAB Display  Ribbon Useful operations  Current Directory List of files  Workspace Defined variable values  Command history Displays what has been typed Command prompt Command Window

4 MATLAB’s Working Directory  Current working directory is where files are saved and run from  When you first start MATLAB, it is a good practice to change the working directory to your Z: drive or USB device  Browse icon available

5 Working with Variables  Variables defined previously can be used to do calculations  Define: a = 8; my_var = 12; >> a + my_var ans = 20 >> a*my_var^2 ans = 1152

6 Rules in Naming Variables  Names must begin with a letter  May contain letters, digits, and the underscore character No spaces are allowed  MATLAB is case sensitive, it distinguishes between uppercase and lowercase letters  Avoid naming variables with currently defined MATLAB functions Ex: exp, sin, cos, sqrt, length, mean, max, min etc.

7 MATLAB Built-in Math Functions  For trigonometric functions, x is entered in radians sin(x), cos(x), asin(x), acos(x), tan(x), cot(x)  To enter x in degrees… sind(x) where x is in degrees  Ex: To calculate sin(/2) >>sin(pi/2)  is defined as “pi” ans = 1

8 Saving a Script File  Script files must be saved after completion  In our class use Save As to your Z:\ or USB drive This should be the same as the working directory you specified upon starting MATLAB SAVE YOUR WORK AS YOU GO!

9 Saving a Script File  The name of the script file is governed by the following rules: No spaces are allowed The name cannot start with a numeric No special characters are allowed (except underscore) Allowed:Not Allowed: Prob1a.mProb 1a.m (blank space) Prob_1a.m1aProb.m (can’t start with numeric) Prob-1a.m (no special characters)

10 Useful Programming Commands  To clear the command window, use “clc” >> clc  To send a text message to the command window or display contents of a variable, use “disp(…)” >> disp(‘Brutus Buckeye’) NOTE: single quotes

11 What is a vector? A vector is an ordered list of several numbers and is a one-dimensional array  Row Vectors are horizontal: [1 2 3 4]  Column Vectors are vertical: [1 2 3 4]

12 Row Vectors vs. Column Vectors  You need to choose which type to create  This will depend on your data and the type of calculations you need to do  If you choose the 'wrong' type, you can transpose your row vector to a column vector, or a column to a row

13 Creating Row Vectors  A row vector is created by typing the elements inside square brackets [ ]  The elements are separated by commas OR spaces  You will likely assign your vector to a variable Remember to use valid variable names

14 Creating Column Vectors  A column vector is separated by typing the elements inside square brackets [ ]  The elements are separated by a semicolon OR by an 'enter'  You will likely assign your vector to a variable Remember to use valid variable names

15 Vector - Vector Math Summary For two vectors x and y : Addition x + yory + x Subtractionx – yory – x Multiplicationx.* yory.* x Divisionx./ yory./ x Exponentx.^ y or y.^ x You must always use the dot operator for Multiplication, Division, and Exponent

16 Function: plot()  Ex: >> plot(x_vec, y_vec)  Will generate a line where x_vec is the vector of x values and y_vec is the vector of corresponding y values

17 Plot Formatting  Title: title('Distance vs. Intensity')  Axis Labels: xlabel('Intensity, w/m^2') ylabel('Distance, m')  Legend: legend('Data Set 1', 'Data Set 2’)


Download ppt "Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All."

Similar presentations


Ads by Google