matlab workshop

37
Workshop on MATLAB Presented By: Prof. Sajid Naeem Department of Electronic Science Poona College -Pune 07/03/20 22 The Language of Technical Computing DOES - PC Coordinator: Prof. Mrs. Angelina Gokhale Organizer: Department of Computer Science (Poona College- Pune) Venue: Computer Lab Date:23 Oct 2012

Upload: esys-india-malegaon

Post on 17-May-2015

744 views

Category:

Education


0 download

DESCRIPTION

Prof. Angelina Gokhale Department of Computer Science Poona College Pune

TRANSCRIPT

Page 1: Matlab workshop

Workshop on

MATLAB

Presented By:Prof. Sajid NaeemDepartment of Electronic SciencePoona College -Pune

04/12/2023

The Language of Technical Computing

DOES - PC

Coordinator: Prof. Mrs. Angelina GokhaleOrganizer: Department of Computer Science (Poona College-Pune)Venue: Computer LabDate:23 Oct 2012

Page 2: Matlab workshop

Introduction:

MATLAB = MATrix LABoratory It is a Numerical Computing environment and Fourth Generation Programming Language developed by “MathWorks” organization.

It allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces and interfacing with programs written in other languages, including  Fortran , C, C++ and Java.

MATLAB is widely used in Academic and Research Institutions as well as Industrial Enterprises.

DOES - PC

Page 3: Matlab workshop

UniversitiesIndustries

Page 4: Matlab workshop

Applications of MATLAB:

Page 5: Matlab workshop

MathWorks Academia:MathWorks Book Program for Researcher and Author.

Subjects:

Biosciences and Biomedical Chemistry and Chemical EngineeringCommunications Systems Control Systems Digital Signal Processing Earth Sciences Economics and Computational Finance ElectronicsImage and Video Processing

Mathematics Mechanical Engineering Neural Networks and Fuzzy Logic Physics Programming and Computer Science Statistics and Probability System Identification System Modeling and SimulationTest and Measurement

Page 6: Matlab workshop

MathWorks for Students:

•Online Training Free and Paid•Competitions•Online Programming Contest•Challenges •Trail Software•Free Books, Tutorials, Research Papers & Articles •Free Training Kits•Online Solutions •Career Opportunities

Page 7: Matlab workshop

MATLAB Basics Elements:• Array: A collection of data values organized into rows

and columns, and known by a single name.

Row 1

Row 2

Row 3

Row 4

Col 1 Col 2 Col 3 Col 4 Col 5

arr(3,2)

DOES - PC

Page 8: Matlab workshop

Arrays:

• The fundamental unit of data in MATLAB

• Scalars are also treated as arrays by MATLAB (1 row and 1 column).

• Row and column indices of an array start from 1.

• Arrays can be classified as vectors and matrices.

DOES - PC

Page 9: Matlab workshop

• Vector: Array with one dimension

• Matrix: Array with more than one dimension

• Size of an array is specified by the number of rows and the number of columns, with the number of rows mentioned first (For example: n x m array).

Total number of elements in an array is the product of the number of rows and the number of columns.

DOES - PC

Page 10: Matlab workshop

1 23 45 6

a= 3x2 matrix 6 elements

b=[1 2 3 4] 1x4 array 4 elements, row vector

c=135

3x1 array 3 elements, column vector

a(2,1)=3 b(3)=3 c(2)=3

Row # Column #

Examples:

DOES - PC

Page 11: Matlab workshop

Matrices• a vector x = [1 2 5 1]

x = 1 2 5 1

• a matrix x = [1 2 3; 5 1 4; 3 2 -1]

x = 1 2 3 5 1 4 3 2 -1

• transpose y = x.’ y =

12

51

DOES - PC

Page 12: Matlab workshop

• x(i,j) subscription

• whole row

• whole column

y=x(2,3)

y =

4

y=x(3,:)

y =

3 2 -1

y=x(:,2)

y =

2

1

2

DOES - PC

Page 13: Matlab workshop

Arithmetic Operators:

variable_name = expression;

+ addition- subtraction* multiplication/ division^ power‘ complex conjugate

transpose

.* element-by-element mul

./ element-by-element div

.^ element-by-element power

.‘ transpose

DOES - PC

Page 14: Matlab workshop

Relational & Logical Operators:

== equal~= not equal< less than<= less than or equal> greater than>= greater than or

equal

& AND| OR~ NOT

1

pi 3.14159265…j imaginary unit, i same as j

DOES - PC

Page 15: Matlab workshop

Variables:

• A region of memory containing an array, which is known by a user-specified name.

• Contents can be used or modified at any time.

• Variable names must begin with a letter, followed by any combination of letters, numbers and the underscore (_) character. Only the first 31 characters are significant.

• The MATLAB language is Case Sensitive. NAME, name and Name are all different variables.

Note: Give meaningful (descriptive and easy-to-remember) names for the variables. Never define a variable with the same name as a MATLAB function or command.

DOES - PC

Page 16: Matlab workshop

Initializing Variables in Assignment StatementsAn assignment statement has the general form

var = expression

Examples:

>> var = 40 * i; >> a2 = [0 1+8];>> var2 = var / 5; >> b2 = [a2(2) 7 a];>> array = [1 2 3 4]; >> c2(2,3) = 5;>> x = 1; y = 2; >> d2 = [1 2];>> a = [3.4]; >> d2(4) = 4;>> b = [1.0 2.0 3.0 4.0];>> c = [1.0; 2.0; 3.0];>> d = [1, 2, 3; 4, 5, 6]; ‘;’ semicolon suppresses the>> e = [1, 2, 3 automatic echoing of values but 4, 5, 6]; it slows down the execution.

DOES - PC

Page 17: Matlab workshop

Initializing of Expressions:

first: increment: last• Colon operator: a shortcut notation used to initialize

arrays with thousands of elements

>> x = 1 : 2 : 10;>> angles = (0.01 : 0.01 : 1) * pi;

• Transpose operator: (′) swaps the rows and columns of an array

>> f = [1:4]′;>> g = 1:4; >> h = [ g′ g′ ];

1 12 23 34 4

h=

DOES - PC

Page 18: Matlab workshop

Initializing with Keyboard Input:

• The input function displays a prompt string in the Command Window and then waits for the user to respond.

my_val = input( ‘Enter an input value: ’ );

in1 = input( ‘Enter data: ’ );

in2 = input( ‘Enter data: ’ ,`s`);

DOES - PC

Page 19: Matlab workshop

Special Values:

• pi: value up to 15 significant digits• i, j: sqrt(-1)• Inf: infinity (such as division by 0)• NaN: Not-a-Number (division of zero by zero)• clock: current date and time in the form of a 6-element

row vector containing the year, month, day, hour, minute, and second

• date: current date as a string such as 3-Oct-2012• eps: epsilon is the smallest difference between two

numbers• ans: stores the result of an expression

DOES - PC

Page 20: Matlab workshop

The Display Function:

disp( array )

>> disp( ‘Hello' )

Hello

>> disp(5)

5

>> disp( [ ‘Poona ' ‘College' ] )

Poona College

>> name = ‘Students';

>> disp( [ 'Hello ' name ] )

Hello StudentsDOES - PC

Page 21: Matlab workshop

The Print function:

fprintf( format, data )– %d integer– %f floating point format– %e exponential format– %g either floating point or exponential

format, whichever is shorter– \n new line character– \t tab character

DOES - PC

Page 22: Matlab workshop

>> fprintf( 'Result is %d', 3 )Result is 3>> fprintf( 'Area of a circle with radius %d is %f', 3, pi*3^2 )Area of a circle with radius 3 is 28.274334>> x = 5;>> fprintf( 'x = %3d', x )x = 5>> x = pi;>> fprintf( 'x = %0.2f', x )x = 3.14>> fprintf( 'x = %6.2f', x )x = 3.14>> fprintf( 'x = %d\ny = %d\n', 3, 13 )x = 3y = 13

DOES - PC

Page 23: Matlab workshop

Built-in MATLAB Functions:• result = function_name( input );

– abs, sign– log, log10, log2– exp– sqrt– sin, cos, tan– asin, acos, atan– max, min– round, floor, ceil, fix– mod, rem

• help elfun help for elementary math functions

DOES - PC

Page 24: Matlab workshop

Types of errors in MATLAB programs:• Syntax errors

– Check spelling and punctuation• Run-time errors

– Check input data– Can remove “;” or add “disp” statements

• Logical errors– Use shorter statements– Check typos– Check units– Ask your teacher, friends, assistants, instructor, …

DOES - PC

Page 25: Matlab workshop

04/12/2023Flow Control:

• Logic Control:

– IF / ELSEIF / ELSE

– SWITCH / CASE / OTHERWISE• Iterative Loops:

– FOR

–WHILE

Page 26: Matlab workshop

MATLAB Desktop:

Menu and toolbar

CommandHistory

Workspace

DOES - PC

Page 27: Matlab workshop

Basic Elements of Matlab’s Desktop:

• Command Windows: Where all commands and programs are run. Write the command or program name and hit Enter.

• Command History: Shows the last commands run on the Command Windows. A command can be recovered clicking twice

• Current directory: Shows the directory where work will be done.

• Workspace: To see the variables in use and their dimensions (if working with matrices)

• Help (can also be called from within the comand windows)

• Matlab Editor: All Matlab files must end in the .m extension.

DOES - PC

Page 28: Matlab workshop

Some Useful MATLAB commands:

• Edit Editor• Exit Close• Quit Close• who List known variables• whos List known variables plus their size• help Ex: >> help sqrt Help on using sqrt• lookfor Ex: >> lookfor sqrt Search for

keyword sqrt in m-files• what Ex:>> what a: List MATLAB files in a:• clear Clear all variables from work space• clear x y Clear variables x and y from work space• clc Clear the command window

DOES - PC

Page 29: Matlab workshop

• what List all m-files in current directory• dir List all files in current directory• ls Same as dir• type test Display test.m in command window• delete test Delete test.m• cd a: Change directory to a:• chdir a: Same as cd• pwd Show current directory• which test Display current directory path to test.m

• Why In case you ever needed a reasonA Useless, But Interesting, MATLAB command

DOES - PC

Page 30: Matlab workshop

Help Window:

Page 31: Matlab workshop

Problems & Solutions:

1. Mathematical Formulae in MATLAB

2. Plotting the Graphs

3. Generation of Signals

4. Image Processing

5. Data Acquisition

6. Communication

7. Aerospace

8. Bioinformatics

9. Embedded System

10. Fuzzy Analysis

11. …

12. .......

DOES - PC

Page 32: Matlab workshop

Next Sessions……….

1) Plotting Graphs

2) Signal Generation

3) Image Processing

4) Assignments……………

DOES - PC

Page 33: Matlab workshop

Who is the Father of Computer?

DOES - PC

Page 34: Matlab workshop

Charles Babbage

DOES - PC

Page 35: Matlab workshop

DOES - PC

Page 36: Matlab workshop

Reference:

http://www.mathworks.in/

Page 37: Matlab workshop

Acknowledgement :I have great pleasure in presenting

the lecture on “MATLAB”. I express my sincere thanks and gratitude to Prof. Z B Pathan (H.O.D) and Prof. Mehtab Alam (H.O.D) to their kind co operation.

Finally I extend our thanks to Principal Dr. G M Nazeruddin for providing necessary facilities in the department to conduct the workshop.

Prof. SAJID NAEEM DOES-PC