Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fourth Year – Software Engineering

Similar presentations


Presentation on theme: "Fourth Year – Software Engineering"— Presentation transcript:

1 Fourth Year – Software Engineering
Image Processing Fourth Year – Software Engineering Introduction

2 Introduction Menu bar Tool bar Current directory Work space
Current folder Command window History command

3 Introduction Cont. version
Pwd (returns the current folder as a character vector to currentFolder .) Cd (Change working directory) cd .. cd D:\ mkdir D:\name clc clear exit or quit help about Lookfor (to search functions for keyword.)

4 Entering Commands The MATLAB command prompt: >> At this prompt you can enter commands to: – Create or modify a variable: E.g. A = 3 – Perform a computation: E.g – Call a function: E.g. max([1 2 3]) – Get help: E.g. help, help max – Save workspace variables: E.g. save Afile A – and some other things.

5 Variables and basic arithmetic Variables are declared at any time in your code. Simply use = operator E.g. A=3 MATLAB is much like any other language for performing basic arithmetic MATLAB can perform arithmetic directly at the command line: E.g Strings are declared using ’’: E.g. S = ’string’

6 Returning computation results MATLAB can return a computation to a variable: E.g. >> B = A + 3 B = 6 MATLAB can perform arithmetic directly at the command line: E.g >>1 + 2 ans = 3 No permanent variable is assigned. But the temporary variable ans is returned. (This is an important basic notion of MATLAB)

7 >> A = 3 A = 3 >> A = 3; >> B = A + 3; >> B
Semicolon terminated commands Semicolon typically ends statements in MATLAB. Strictly speaking the return or newline ends the statement (forces evaluation) If semicolon is omitted then the result of the computation is echoed to the command window: >> 6+5 ans = 11 >> 6+5; >> ans; >> ans >> A = 3 A = 3 >> A = 3; >> B = A + 3; >> B B = 6

8 Matrices or Arrays MATLAB works with essentially only one kind of object — a rectangular numerical matrix with possibly complex entries: All variables represent matrices. In some situations, 1-by-1 matrices are interpreted as scalars and matrices with only one row or one column are interpreted as vectors.

9 Introduction Cont. Input a row or column vector a=1 or a=[1] a=[ ] or a=[1,2,3,4] or a=[1:4] or a=[1:1:4] or a= 1:4 a=[1;2;3;4] or a=[ ]’ or a=[1:4]’ b=[1:2:10] b=[10:2:1] input matrix: a=[1 2 ;3 4] or a=[1:2;3:4] or a=[1 2; 3, 4] a=[1 2;3 4]’ a=[ ; ;8:-2:2] Cell array x={[1 2;3 4],[5 6;7 8]} x={[1 2;3 4],[5 6;7 8];[9 10],[11 12]}

10 Introduction Cont. x=[1:4;2:2:8;8:-2:2;4:-1:1] 1 2 3 4 2 4 6 8 8 6 4 2
y= x(3,2) // y=6 y= x(2,:) // y=[ ] y= x(2,3:4) // y= [6 8] y=x(4, 2:end) // [ ] y= x(:,:) //equivalent to x=y y= x(:) //convert x to column vector x=

11 Complex conjugate transpose Specify evaluation order
Introduction Cont. Operation Description + Addition - Subtraction *, .* Multiplication /, ./ Division \, .\ Left division ^, . ^ Power ' Complex conjugate transpose ( ) Specify evaluation order

12 Introduction Cont. x=[2 4;1 3] y=[3 2;4 2] z=x+y // z=[ 5 6;5 5]

13 Introduction create special matrices:
x=ones(3,3) or x=ones(3) x=zeros(2,3) eye(3) // 3*3 identity matrix x=magic(3) y=diag(a) x=rand(3,4) Random matrix contains value between 0-50? fix(x) Round to words zero (2.7=2 & -2.7=-2) floor(x) Round to words minus infinity (2.7=2 & -2.7=-3) ceil(x) Round to words plus infinity (2.7=3 & -2.7=-2) round(x) Round to words nearest integer (2.7=3 & 2.4=2) randperm(10)

14 Introduction x=round(20*rand(4,3)) [m n]=size(x) length(x)
numel(x) // equivalent to m*n repmat(x,2,3) reshape(x,1,[]) //equivalent to reshape(x,1,m*n) y=2*x cat(1,x,y) cat(2,x,y)

15 Introduction max(x) max(x,3) max(x,y) min(x) min(x,4)
sort(x) // sort(x,'descend') or sort(x,‘ascend') mean(x) std(x) sum(x) sqrt(x) nthroot(x,3) mod(x,3) fact(number or matrix)


Download ppt "Fourth Year – Software Engineering"

Similar presentations


Ads by Google