Download presentation
Presentation is loading. Please wait.
1
Lecture: MATLAB Chapter 1 Introduction
Dr. Khalid Kaabneh, Dr. Nidal Youssef
2
Introduction to MATLAB
technical computing environment for numeric computation and visualization. MATLAB is an interactive matrix based system for scientific and engineering numeric computation and visualization. You can solve complex numerical problems in a fraction of the time required with a programming language such as Fortran or C The name MATLAB is derived from MATrix LABoratory Dr. Khalid Kaabneh, Dr. Nidal Youssef
3
Dr. Khalid Kaabneh, Dr. Nidal Youssef
What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for us How high? Assembly High Level Languages such as C, Pascal etc. Matlab Dr. Khalid Kaabneh, Dr. Nidal Youssef
4
What are we interested in?
Matlab is too broad for our purposes in this course. The features we are going to require is Matlab Command Line m-files functions mat-files Command execution like DOS command window Series of Matlab commands Input Output capability Data storage/ loading Dr. Khalid Kaabneh, Dr. Nidal Youssef
5
Dr. Khalid Kaabneh, Dr. Nidal Youssef
Working Memory Command Window Command History Dr. Khalid Kaabneh, Dr. Nidal Youssef
6
Dr. Khalid Kaabneh, Dr. Nidal Youssef
Variables No need for types. i.e., All variables are created with double precision unless specified and they are matrices. After these statements, the variables are 1x1 matrices with double precision int a; double b; float c; Example: >>x=5; >>x1=2; Dr. Khalid Kaabneh, Dr. Nidal Youssef
7
Dr. Khalid Kaabneh, Dr. Nidal Youssef
Single Values The value of two variables can be added together, and the result displayed… >> A = 10 >> A + A …or the result can be stored in another variable >> B = A + A The value of the variable is accessed through it’s name..... Adding A to A adds the values in the variable A (here 10) therefore the result is 20 the result can be stored in a new variable, B, which you can see now has the value 20 Dr. Khalid Kaabneh, Dr. Nidal Youssef 7 7
8
Dr. Khalid Kaabneh, Dr. Nidal Youssef
Single Values Can not do an assignment?? >> 15 = A Error>>>> …or the result can be an arithmetic operation >> A = 4 + 2 A = 6 The value of the variable is accessed through it’s name..... Adding A to A adds the values in the variable A (here 10) therefore the result is 20 the result can be stored in a new variable, B, which you can see now has the value 20 Dr. Khalid Kaabneh, Dr. Nidal Youssef 8 8
9
Dr. Khalid Kaabneh, Dr. Nidal Youssef
Single Values If a variable in the working memory, then we Can do this: >> A = 32 A = 32 >> A = A + 18 … The value of the variable is accessed through it’s name..... Adding A to A adds the values in the variable A (here 10) therefore the result is 20 the result can be stored in a new variable, B, which you can see now has the value 20 Dr. Khalid Kaabneh, Dr. Nidal Youssef 9 9
10
Clear clear command will clear all variables.
clear variablename clears out a particular variable Who will list the variables you have.
11
Number format >> format long >> 2 * sin(1.4) ans =
>> pi >> format short 1.9709 3.1416
12
>> format loose >> 2^7 ans = 128 >> format compact
13
Dr. Khalid Kaabneh, Dr. Nidal Youssef
Expressions in MATLAB Dr. Khalid Kaabneh, Dr. Nidal Youssef 13
14
Dr. Khalid Kaabneh, Dr. Nidal Youssef
Expressions in MATLAB Operators usual set of arithmetic operators * / ^ a few special ones, e.g., * / \ usual set of logical operators: & | ~ Functions large library of built-in functions (e.q. sqrt, abs, sin) e.g., >> x = sqrt(a); Dr. Khalid Kaabneh, Dr. Nidal Youssef
15
Dr. Khalid Kaabneh, Dr. Nidal Youssef
MatLab Operators >> 1 + 3 ans= 4 >> 3 * 4 12 >> 7 / 3 ans= 2.333 >> 7 ^ 3 343 Dr. Khalid Kaabneh, Dr. Nidal Youssef
16
assignment of variables
ans = 5 >> a*b 6 Dr. Khalid Kaabneh, Dr. Nidal Youssef
17
Relational Operators <, <=, >, >=, ==, ~=
compare corresponding elements of arrays with same dimensions if one is scalar, one is not, the scalar is compared with each element result is, element by element, 1 or 0
18
Relational Operators <, <=, >, >=, ==, ~=
compare corresponding elements of arrays with same dimensions if one is scalar, one is not, the scalar is compared with each element result is element by element 1 or 0 » a = [2 3] a = » b=[4,5] b = » a > b ans = » b > a ans = » a > 2 ans =
19
Useful built-in functions
save rand zeros min max load Remember to use the Matlab help command if you get stuck
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.