Download presentation
Presentation is loading. Please wait.
Published byElizabeth Miller Modified over 9 years ago
1
Structured Computer Programming EE 201 Introduction to MATLAB 7 for Engineers بسم الله الرحمن الرحيم King Abdulaziz University College of Engineering Dept of Electrical & Computer Engineering
2
Chapter 1 Lecture 3 Basic Syntax and Command A’ Inverse Matrix A A(n,d) Elements in row n & column d RESHAPE Change size RESHAPE(A,s,z) condition s*z = k*m m columns K rows
3
flipud(A) FLIPUD Flip matrix in up/down direction. FLIPUD(X) returns X with columns preserved and rows flipped in the up/down direction. For example, X = 1 4 becomes 3 6 2 5 2 5 3 6 1 4 fliplr(A) FLIPLR Flip matrix in left/right direction. FLIPLR(X) returns X with row preserved and columns flipped in the left/right direction. X = 1 2 3 becomes 3 2 1 4 5 6 6 5 4
4
Exercise: If x = [3 1 5 7 9 2 6] Summarize the net result of the command. a. x(3) b. x(1:7) c. x(1:end) d. x(1:end-1) e. x(6:-2:1) f. x([1 6 2 1 1]) g. sum(x)
5
Matrix & Array If A = [ a11,a12; a21,a22] & B = [ b11,b12; b21,b22] there is a difference between * and.* * is Matrix multiply A*B = [ a11* b11 + a11 *b21, a12* b11 + a12 *b21, a21* b21 + a21 *b22, a22* b21 + a22 *b22] But.* is Array multiply A.*B = [ a11* b11, a12 *b12 ; a21*b21, a22*b22] Do it by your self and note what is the difference between (./ and / ), (.\ and \ )
6
Extra commands floor Round towards minus infinity. floor(X) rounds the elements of X to the nearest integers towards minus infinity. ceil Round towards plus infinity. ceil(X) rounds the elements of X to the nearest integers towards infinity. fix Round towards zero. fix(X) rounds the elements of X to the nearest integers towards zero. round Round towards nearest integer. round(X) rounds the elements of X to the nearest integers.
7
Getting Help King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi Throughout each chapter margin notes identify where key terms are introduced. Each chapter contains tables summarizing the MATLAB commands introduced in that chapter. At the end of each chapter is a summary guide to the commands covered in that chapter. Appendix A contains tables of MATLAB commands, grouped by category, with the appropriate page references. There are three indexes. The first lists MATLAB commands and symbols, the second lists Simulinkblocks, and the third lists topics.
8
The Help Navigator contains four tabs: Contents: a contents listing tab, Index: a global index tab, Search: a search tab having a find function and full text search features, Demos: a book marking tab to start built-in demonstrations.
9
The MATLAB Help Browser.
10
Help Functions help funcname: Displays in the Command window a description of the specified function funcname. lookfor topic: Displays in the Command window a brief description for all functions whose description includes the specified key word topic. doc funcname: Opens the Help Browser to the reference page for the specified function funcname, providing a description, additional remarks, and examples.
11
Relational operators Relational Meaning operator < Less than. <= Less than or equal to. > Greater than. >= Greater than or equal to. == Equal to. ~= Not equal to.
12
Examples of Relational Operators >> x = [6,3,9]; y = [14,2,9]; >> z = (x < y) z =1 0 0 >>z = ( x > y) z =0 1 0 >>z = (x ~= y) z =1 1 0 >>z = ( x == y) z =0 0 1 >>z = (x > 8) z =0 0 1
13
The find Function find(x) computes an array containing the indices of the non zero elements of the numeric array x. For example >>x = [-2, 0, 4]; >>y = find(x) y =1 3 The resulting array y = [1, 3]indicates that the first and third elements of x are nonzero.
14
Note the difference between the result obtained by x(x<y) and the result obtained by find(x<y). >>x = [6,3,9,11];y = [14,2,9,13]; >>values = x(x<y) values =6 11 >>how_many = length(values) how_many =2 >>indices = find(x<y) indices =1 4
15
Extra in Plotting rectangular Paper semi log paper (logarithm on the y-axis) log-log paper
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.