Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 MATLAB 입문 An Overview of MATLAB. An Overview of MATLAB 2 Starting Matlab The default MATLAB Desktop.

Similar presentations


Presentation on theme: "1 MATLAB 입문 An Overview of MATLAB. An Overview of MATLAB 2 Starting Matlab The default MATLAB Desktop."— Presentation transcript:

1 1 MATLAB 입문 An Overview of MATLAB

2 An Overview of MATLAB 2 Starting Matlab The default MATLAB Desktop.

3 An Overview of MATLAB 3 Operations (1/2) SymbolOperationMATLAB form ^exponentiation:a^b *multiplication:a*b /right division:a/b \left division:a\b +addition:a+b -subtraction:a-b Scalar arithmetic operations

4 An Overview of MATLAB 4 Operations (2/2)

5 An Overview of MATLAB 5 assignment, workspace, and command The sign ‘=‘ is called the ‘assignment or replacement’ operator.  e.g. x = 3 : assign the value 3 to the variable x x = x + 2 : add 2 to the current value of x Workspace : the names and values of any variables in use in the current work session Commands for managing the work session clc clears the Command window clear Removes all variables from memory exist(‘name’) Determines if a file or variable exists having the name ’name’ quit Stops MATLAB who Lists the variable currently in memory whos Lists the current variables and sizes, and indicates if they have imaginary parts : Colon; generates and array having regularly spaced elements, Comma; separates elements of an array ; Semicolon; suppresses screen printing; also denotes a new row in an array … Ellipsis; continues a line

6 An Overview of MATLAB 6 recall feature, and special variable recall feature  recall a previously typed function or variable  e.g. up-arrow key(↑) & down-arrow key(↓): move up and down through the previously typed lines one line at a time. Tab key: automatically completes the name of a function, variable, or file if you type the first few letters of the name and press the Tab key. Special variables and constants ans Temporary variable containing the most recent answer eps Specifies the accuracy of floating point precision i, j The imaginary unit Inf Infinity NaN Indicates an undefined numerical result pi The number π

7 An Overview of MATLAB 7 Complex Number Operations

8 An Overview of MATLAB 8 Formatting Commands The Format command controls how numbers appear on the screen. format short Four decimal digits (the default); 13.6745 format long 16 digits; 17.27484029463547 format short e Five digits (four decimals) plus exponent; 6.3793e+03 format long e 16 digits (15 decimals) plus exponent; 6.379243784781294e-04 format bank Two decimal digits; 126.73 format + Positive, negative, or zero; + format rat Rational approximation; 43/7 format compact Suppresses some line feeds format loose Resets to less compact display mode

9 An Overview of MATLAB 9 Array(1/2) One of the strengths of MATLAB is its ability to handle collections of numbers, called arrays. A numerical array is an ordered collection of numbers We can use square brackets  e.g. >> x = [0, 1, 3, 6] You need not type all the numbers in the array if they are regularly spaced  e.g. >> u = [0: 0.1: 10]  u = [0, 0.1, 0.2, 0.3, …, 9.8, 9.9, 10]

10 An Overview of MATLAB 10 Array(2/2) You can compute ‘w=5*sin (u)’ for ‘u=[0: 0.1: 10]’ >> u=[0: 0.1: 10]; >> w=5*sin(u);  computed the formula ‘w=5*sin(u)’ 101 times. array index: points to a particular element in the array >>u(7) ans = 0.6000 >>w(7) ans = 2.8232 length: determine how many values are in an array >>m = length(w) m = 101

11 An Overview of MATLAB 11 Mathematical functions Some commonly used mathematical functions FunctionMATLAB syntax ( ◈ ) exp(x) sqrt(x) log(x) log10(x) cos(x) sin(x) tan(x) acos(x) asin(x) atan(x) ◈ The MATLAB trigonometric functions use radian measure

12 An Overview of MATLAB 12 Working with Files M-file: MATLAB function files and program files are saved with the extension.m, and called M-files. MAT-file: save the names and values of variables. ASCII-file: files written in a specific format designed to make them usable to a wide variety of software.

13 An Overview of MATLAB 13 System, directory, and file commands system, directory, and file commands addpath dirname Adds the directory dirname to the search path. cd dirname Changes the current directory to dirname. dir Lists all files in the current directory. dir dirname Lists all the files in the directory dirname. path Displays the MATLAB search path. pathtool Starts the Set Path tool. pwd Displays the current directory. rmpath dirname Removes the directory dirname from the search path. what Lists the MATLAB-specific files found in the current working directory. Most data files and other non-MATLAB files are not listed. Use dir to get a list of all files. what dirname Lists the MATLAB-specific files in directory dirname.

14 An Overview of MATLAB 14 Plotting commands Some MATLAB plotting commands [x, y] = ginput(n) Enables the mouse to get n points from a plot, and returns the x and y coordinates in the vectors x and y, which have a length n. grid puts grid lines on the plot. gtext (‘text’) Enables placement of text with the mouse. plot (x, y) Generates a plot of the array y versus the array x on rectilinear axes. title (‘text’) Puts text in a title at the top of the plot. xlabel (‘text’) Adds a text label to the horizontal axis (the abscissa). ylabel (‘text’) Adds a text label to the vertical axis (the ordinate).

15 An Overview of MATLAB 15 Plotting with MATLAB

16 An Overview of MATLAB 16 Linear Algebra Equations the left division operator(\)  e.g.

17 An Overview of MATLAB 17 Statistics, Calculus, and Processing Statistics  perform statistical calculations and other types of data manipulation. Numerical Calculus, Differential Equations, and Simulink  MATLAB can numerically compute the derivative and the integral Symbolic Processing  obtain the derivative and the integral in symbolic form (a formula instead of as a set of numerical values)

18 An Overview of MATLAB 18 Script Files and the Editor/Debugger(1/2) Two ways for performing operations in MATLAB  Interactive mode : directly enter the commands in the Command window  using script files (commands files) : store the commands in script files M-files  script files :when need to use many commands or arrays with many elements  function files :when need to repeat the operation of a set of commands

19 An Overview of MATLAB 19 Script Files and the Editor/Debugger(2/2) M-file 생성 및 저장

20 An Overview of MATLAB 20 Input/output commands disp (A) Displays the contents, but not the name, of the array A. disp (‘text’) Displays the text string enclosed within single quotes. format Controls the screen’s output display format fprintf Performs formatted writes to the screen or to a file x = input (‘text’) Displays the text in quotes, waits for user input from the keyboard, and stores the value in x. x = input (‘text’, ’s’) Displays the text in quotes, waits for user input from the keyboard, and stores the input as a string in x k = menu (‘title’,’option1’,’option2’,…) Displays a menu whose title is in the string variable ‘title’, and whose choices are ‘option1’,’option2’, and so on.

21 An Overview of MATLAB 21 The MATLAB Help System(1/4) Help Browser  Graphical user interface  find information, view online documentation Help Functions  help, lookfor, doc  display syntax information for specified function Other Resources  run demos, contact technical support, participate in a newsgroup.  The MathWorks Website the home of MATLAB. http://www.mathworks.com

22 An Overview of MATLAB 22 The MATLAB Help System(2/4) - Help Browser The MATLAB Help Browser  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 bookmaking tab to start built-in demonstrations

23 An Overview of MATLAB 23 The MATLAB Help System(3/4) - Help Functions MATLAB Help functions (help, lookfor, doc) FunctionUse docDisplays the start page of the documentation in the Help Browser doc functionDisplays the documentation for the MATLAB function function doc toolbox/functionDisplays the documentation for the specified toolbox function doc toolboxDisplays the documentation road map page for the specified toolbox helpDisplays a list all the function directories, with a description of the function category each represents. help functionDisplays in the Command window a description of the specified function function helpwin topicDisplays the help text for the specified topic inside the desktop Help Browser window lookfor topicDisplays in the Command window a brief description for all functions whose description includes the specified keyword topic type filenameDisplays the M-file filename without opening it with a text editor.

24 An Overview of MATLAB 24 The MATLAB Help System(4/4) - Help Functions Examples

25 An Overview of MATLAB 25 Programming in MATLAB(1/5) Relational operators  to make comparisons . >=, ==, ~= Conditional statements  to write programs that make decisions  if, else, elseif Loops  a structure for reputation a calculation a number of times  for, while

26 An Overview of MATLAB 26 Programming in MATLAB(2/5) Relational operatorMeaning <Less than <=Less than or equal to >Greater than >=Greater than or equal to ==Equal to ~=Not equal to >> 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 = 0 0 1 >> z = (x ~= y) z = 1 1 0 >> z = (x > 8) z = 0 0 1 Relational Operators

27 An Overview of MATLAB 27 Programming in MATLAB(3/5) The find Function  find(x) : computes an array containing the indices of the nonzero elements of the numeric array x  the find function returns the indices, not the values. >> x = [-2, 0, 4]; >> y = find(x) y = 1 3 >> 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

28 An Overview of MATLAB 28 Programming in MATLAB(4/5) Conditional Statements  contain one or more of the if, else, and elseif  The end statement denotes the end of a conditional statement  The else and elseif statements may be omitted if not required. if x >= 9 y = 15*sqrt(4x) + 10 elseif x >= 0 y = 10*x + 10 else y = 10 end if expression commands elseif expression commands else commands end

29 An Overview of MATLAB 29 Programming in MATLAB(5/5) Loops  repeat a calculation a number of times  for loop : the number of passes is known ahead of time  while loop : the looping process must terminate when a specified condition is satisfied m = 0; x(1) = 10; for k = 2:3:11 m = m+1; x(m+1) = x(m) + k^2; end x(1) = 14, x(2) = 39, x(3) = 103, x(4) = 224 x = 5; k = 0; while x < 25 k = k+1; y(k) = 3*x; x = 2*x-1; end y(1) = 15, y(2) = 27, y(3) = 51


Download ppt "1 MATLAB 입문 An Overview of MATLAB. An Overview of MATLAB 2 Starting Matlab The default MATLAB Desktop."

Similar presentations


Ads by Google