Matlab workshop
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Matlab workshop

on

  • 742 views

Workshop on MATLAB at the Department of Computer Science, Poona College, Pune

Workshop on MATLAB at the Department of Computer Science, Poona College, Pune

Statistics

Views

Total Views
742
Views on SlideShare
742
Embed Views
0

Actions

Likes
0
Downloads
52
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Matlab workshop Presentation Transcript

  • 1. 10/23/2012 Workshop on MATLAB The Language of Technical Computing Prof. Sajid Naeem Department of Electronic ScienceDOES - PC Poona College -Pune
  • 2. 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
  • 3. Industries Universities
  • 4. Applications of MATLAB:
  • 5. MathWorks Academia:MathWorks Book Program for Researcher and Author.Subjects:Biosciences and Biomedical Mathematics Chemistry and Chemical Engineering Mechanical EngineeringCommunications Systems Neural Networks and Fuzzy Logic Control Systems Physics Digital Signal Processing Programming and Computer Science Earth Sciences Statistics and Probability Economics and Computational Finance System Identification System Modeling Electronics and SimulationImage and Video Processing Test and Measurement
  • 6. 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
  • 7. 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 arr(3,2) Row 4 Col 1 Col 2 Col 3 Col 4 Col 5DOES - PC
  • 8. 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
  • 9. • 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
  • 10. Examples: 1 2 a= 3 4 3x2 matrix  6 elements 5 6 b=[1 2 3 4] 1x4 array  4 elements, row vector 1 c= 3 3x1 array  3 elements, column vector 5 a(2,1)=3 b(3)=3 c(2)=3 Row # Column #DOES - PC
  • 11. 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 = 1 2 5 1DOES - PC
  • 12. y=x(2,3) • x(i,j) subscription y = 4 y=x(3,:) y = 3 2 -1 • whole row y=x(:,2) y = 2 1 • whole column 2DOES - PC
  • 13. Arithmetic Operators: variable_name = expression; + addition .* element-by-element mul - subtraction ./ element-by-element div * multiplication .^ element-by-element power / division .‘ transpose ^ power ‘ complex conjugate transposeDOES - PC
  • 14. Relational & Logical Operators: == equal pi 3.14159265… ~= not equal j imaginary unit, 1 < less than i same as j <= less than or equal > greater than >= greater than or equal & AND | OR ~ NOTDOES - PC
  • 15. 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
  • 16. Initializing Variables in Assignment Statements An 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
  • 17. 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 1 1 >> f = [1:4]′; 2 2 h= >> g = 1:4; 3 3 >> h = [ g′ g′ ]; 4 4DOES - PC
  • 18. 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
  • 19. 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 expressionDOES - PC
  • 20. The Display Function: disp( array ) >> disp( „Hello ) Hello >> disp(5) 5 >> disp( [ „Poona „College ] ) Poona College >> name = „Students; >> disp( [ Hello name ] ) Hello StudentsDOES - PC
  • 21. 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 characterDOES - PC
  • 22. >> 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 = %dny = %dn, 3, 13 ) x=3 y = 13DOES - PC
  • 23. 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 functionsDOES - PC
  • 24. 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
  • 25. 10/23/2012Flow Control:• Logic Control: – IF / ELSEIF / ELSE – SWITCH / CASE / OTHERWISE• Iterative Loops: – FOR – WHILE
  • 26. MATLAB Desktop: Menu and toolbarWorkspace History CommandDOES - PC
  • 27. 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
  • 28. 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 windowDOES - PC
  • 29. • 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 A Useless, But Interesting, MATLAB command • Why In case you ever needed a reasonDOES - PC
  • 30. Help Window:
  • 31. 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
  • 32. Next Sessions………. 1) Plotting Graphs 2) Signal Generation 3) Image Processing 4) Assignments……………DOES - PC
  • 33. Who is the Father of Computer?DOES - PC
  • 34. Charles BabbageDOES - PC
  • 35. DOES - PC
  • 36. Reference: http://www.mathworks.in/
  • 37. Acknowledgement : I have great pleasure in presentingthe lecture on “MATLAB”. I express mysincere thanks and gratitude to Prof. Z BPathan (H.O.D) and Prof. Mehtab Alam(H.O.D) to their kind co operation. Finally I extend our thanks toPrincipal Dr. G M Nazeruddin for providingnecessary facilities in the department toconduct the workshop. Prof. SAJID NAEEM DOES-PC