Download presentation

Presentation is loading. Please wait.

Published byAron Foster Modified over 4 years ago

1
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB http://www.etcs.ipfw.edu/~lin

2
January 24, 2005 Lecture 3 - By P. Lin 2 Lecture 3: MATLAB Development Environment 3-1 Desktop Tools 3-1 Desktop Tools Starting and Quitting MATLABStarting and Quitting MATLAB Command WindowCommand Window Running Functions Running Functions Entering Variables Entering Variables Controlling Input/Output Controlling Input/Output Searching Items Searching Items Running Programs Running Programs Preferences for the Command Window Preferences for the Command Window

3
January 24, 2005 Lecture 3 - By P. Lin 3 Lecture 3: MATLAB Development Environment (continue) 3-1 Desktop Tools (continue) 3-1 Desktop Tools (continue) Command HistoryCommand History The MATLAB WorkspaceThe MATLAB Workspace Help BrowserHelp Browser Workspace BrowserWorkspace Browser Current Directory BrowserCurrent Directory Browser Edit/DebugEdit/Debug

4
January 24, 2005 Lecture 3 - By P. Lin 4 Lecture 3: MATLAB Development Environment (continue) 3-2 Useful Commands 3-2 Useful Commands The MATLAB Search PathThe MATLAB Search Path Number Display FormatsNumber Display Formats Session LogSession Log MATLAB Managing Commands and FunctionsMATLAB Managing Commands and Functions demo - Run demos demo - Run demos help- Online help help- Online help ver - Current MATLAB and toolbox versions ver - Current MATLAB and toolbox versions version - Current MATLAB version number version - Current MATLAB version number path- MATLAB Search path path- MATLAB Search path diary- Save typed commands on a named file diary- Save typed commands on a named file Summary Summary

5
January 24, 2005 Lecture 3 - By P. Lin 5 Starting and Quitting MATLAB Starting MATLAB From command window: start -> Run -> MATLAB From command window: start -> Run -> MATLAB Start -> All Programs -> MATLAB Start -> All Programs -> MATLAB

6
January 24, 2005 Lecture 3 - By P. Lin 6 Starting and Quitting MATLAB Quitting MATLAB At the MATLAB command window: At the MATLAB command window: >> quit >> exit Close MATLAB Window Close MATLAB Window

7
January 24, 2005 Lecture 3 - By P. Lin 7 Desktop Tools Started MATLAB and see the three sub-windows: Command Window Command Window Current Directory Current Directory Command History Command History At the command window, we enter >>help help

8
January 24, 2005 Lecture 3 - By P. Lin 8 Command Window Running Functions Running Functions Entering Variables Entering Variables Controlling Input/Output Controlling Input/Output Searching Items Searching Items Running Programs Running Programs Setting Preferences for the Command Window Setting Preferences for the Command Window

9
January 24, 2005 Lecture 3 - By P. Lin 9 Running Commands An Example: >> magic(3) ans = 8 1 6 3 5 7 3 5 7 4 9 2 4 9 2 >> help magic MAGIC Magic square. MAGIC Magic square. MAGIC(N) is an N-by-N matrix constructed from the integers MAGIC(N) is an N-by-N matrix constructed from the integers 1 through N^2 with equal row, column, and diagonal sums. 1 through N^2 with equal row, column, and diagonal sums. Produces valid magic squares for all N > 0 except N = 2. Produces valid magic squares for all N > 0 except N = 2. 15

10
January 24, 2005 Lecture 3 - By P. Lin 10 Entering Variables >> x = 10 x = 10 >> y = 10 y = 10 >> x * y ans = 100 >> x / y ans = 1 >> x + y ans = 20 >> x - y ans = 0 >>

11
January 24, 2005 Lecture 3 - By P. Lin 11 Controlling Input/Output Format Function – control the display formats for numeric values Format Function – control the display formats for numeric values Examples Examples >> x = 1/3 x = 0.3333 x = 0.3333 >> y = 1.2345e-7 y = 1.2345e-7 y = 1.2345e-7 >> format short e >> x x = 3.3333e-001 >> y y = 1.2345e-007 Hit Enter key MATLAB Displays Hit Enter key MATLAB Displays Hit Enter key Enter x Enter y MATLAB Echoes

12
January 24, 2005 Lecture 3 - By P. Lin 12 Controlling Input/Output (continue) Format Function: Format Function: >> help format FORMAT Set output format. FORMAT Set output format. All computations in MATLAB are done in double precision. All computations in MATLAB are done in double precision. FORMAT may be used to switch between different output FORMAT may be used to switch between different output display formats as follows: display formats as follows: FORMAT Default. Same as SHORT. FORMAT Default. Same as SHORT. FORMAT SHORT Scaled fixed point format with 5 digits. FORMAT SHORT Scaled fixed point format with 5 digits. FORMAT LONG Scaled fixed point format with 15 digits. FORMAT LONG Scaled fixed point format with 15 digits. FORMAT SHORT E Floating point format with 5 digits. FORMAT SHORT E Floating point format with 5 digits. FORMAT LONG E Floating point format with 15 digits. FORMAT LONG E Floating point format with 15 digits. >> format long >> x x = 0.33333333333333 >> y y = 1.234500000000000e- 007

13
January 24, 2005 Lecture 3 - By P. Lin 13 Controlling Input/Output (continue) Format Function: Format Function: >> help format … FORMAT SHORT G Best of fixed or floating point format with 5 digits. … FORMAT SHORT G Best of fixed or floating point format with 5 digits. FORMAT LONG G Best of fixed or floating point format with 15 digits. FORMAT LONG G Best of fixed or floating point format with 15 digits. FORMAT HEX Hexadecimal format. FORMAT HEX Hexadecimal format. FORMAT + The symbols +, - and blank are printed for positive, negative and zero elements. Imaginary parts are ignored. FORMAT + The symbols +, - and blank are printed for positive, negative and zero elements. Imaginary parts are ignored. FORMAT BANK Fixed format for dollars and cents. FORMAT BANK Fixed format for dollars and cents. FORMAT RAT Approximation by ratio of small integers. FORMAT RAT Approximation by ratio of small integers. >> format long g >> x x = 0.333333333333333 >> y y = 1.2345e- 007 >> format bank >> x x = 0.33 >> y y = 0.00 >> format rat >> x x = 1/3 >> y y = 1/8100446

14
January 24, 2005 Lecture 3 - By P. Lin 14 Controlling Input/Output (continue) File -> Preferences Allows you to set up various numeric display formats through GUIAllows you to set up various numeric display formats through GUI

15
January 24, 2005 Lecture 3 - By P. Lin 15 Suppress Output Suppressing Output Suppressing Output End of the statement with a semicolonEnd of the statement with a semicolon Increase statement and program execution speedIncrease statement and program execution speed An Example An Example >> x = 10; >> y = 10; >> product = x * y Product = 100

16
January 24, 2005 Lecture 3 - By P. Lin 16 Entering long Statements If a statement does not fit on a line (too long), uses an ellipsis (three periods), follow by Enter or Return, to indicate the continuation of the statement to the next line If a statement does not fit on a line (too long), uses an ellipsis (three periods), follow by Enter or Return, to indicate the continuation of the statement to the next line For an example For an example >> x = 1 + 2 + 3 + 5 + 6 + 7 +... 8 + 9 + 10 x = 51 51

17
January 24, 2005 Lecture 3 - By P. Lin 17 Command Line Editing and Command History Command Line Editing Command Line Editing Keys such as right arrow →, down arrow ↓, up arrow ↑, left arrow ←, etc, can be used to edit commands Command History Command History The entered commands at the Command Windows are recorded or logged in the Command HistoryThe entered commands at the Command Windows are recorded or logged in the Command History We can view previous commands or statementsWe can view previous commands or statements We can copy or execute rerun previous statementsWe can copy or execute rerun previous statements

18
January 24, 2005 Lecture 3 - By P. Lin 18 The MATLAB Workspace who function who function whos function whos function clear function clear function >> who Your variables are: x y >> whos Name Size Bytes Class x 1x1 8 double array y 1x1 8 double array Grand total is 2 elements using 16 bytes >> clear x >> who Your variables are: y >> clear >> whos

19
January 24, 2005 Lecture 3 - By P. Lin 19 The MATLAB Workspace save function save function load function load function >> save 8_20_2004.mat >> clear >> whos >> load 8_20_2004.mat >> whos Name Size Bytes Class ans 1x1 8 double array x 1x1 8 double array y 1x1 8 double array Grand total is 3 elements using 24 bytes >> clear >> whos Current Directory

20
January 24, 2005 Lecture 3 - By P. Lin 20 Save Command We can use “help save” to see documentation of SAVE function and learn how to Save workspace variables to disk. We can use “help save” to see documentation of SAVE function and learn how to Save workspace variables to disk. SAVE FILENAME saves all workspace variables to the binary "MAT-file“, If FILENAME has no extension,.mat is assumed.SAVE FILENAME saves all workspace variables to the binary "MAT-file“, If FILENAME has no extension,.mat is assumed. SAVE, by itself, creates the binary "MAT-file" named 'matlab.mat'. It is an error if 'matlab.mat' is not writable. SAVE, by itself, creates the binary "MAT-file" named 'matlab.mat'. It is an error if 'matlab.mat' is not writable. SAVE FILENAME X saves only X. SAVE FILENAME X saves only X. SAVE FILENAME X Y Z saves X, Y, and Z. The wildcard '*' can be used to save only those variables that match a pattern. SAVE FILENAME X Y Z saves X, Y, and Z. The wildcard '*' can be used to save only those variables that match a pattern.

21
January 24, 2005 Lecture 3 - By P. Lin 21 Save Command (continue) MATLAB also offers various saving options: ASCII Options: ASCII Options: SAVE... -ASCII uses 8-digit ASCII form instead of binary regardless of file extension.SAVE... -ASCII uses 8-digit ASCII form instead of binary regardless of file extension. SAVE... -ASCII -DOUBLE uses 16-digit ASCII form.SAVE... -ASCII -DOUBLE uses 16-digit ASCII form. SAVE... -ASCII -TABS delimits with tabs.SAVE... -ASCII -TABS delimits with tabs. And more will be discussed later And more will be discussed later

22
January 24, 2005 Lecture 3 - By P. Lin 22 Help Browser

23
January 24, 2005 Lecture 3 - By P. Lin 23 Workspace Browser

24
January 24, 2005 Lecture 3 - By P. Lin 24 Current Directory Browser

25
January 24, 2005 Lecture 3 - By P. Lin 25 The Edit/Debug Use the Editor/Debugger to create and debug M-files, which are programs you write to run MATLAB functions. Use the Editor/Debugger to create and debug M-files, which are programs you write to run MATLAB functions. The Editor/Debugger provides a graphical user interface for basic text editing, as well as for M-file debugging. The Editor/Debugger provides a graphical user interface for basic text editing, as well as for M-file debugging.

26
January 24, 2005 Lecture 3 - By P. Lin 26 The Edit/Debug (continue)

27
January 24, 2005 Lecture 3 - By P. Lin 27 The Edit/Debug (continue) Create a mlab_exs directory Save the M-file as sine60hz.m

28
January 24, 2005 Lecture 3 - By P. Lin 28 The Edit/Debug (continue)

29
January 24, 2005 Lecture 3 - By P. Lin 29 Testing/Debugging sin60hz.m Click -> Debug -> Run

30
January 24, 2005 Lecture 3 - By P. Lin 30 Other Commands Other Useful MATLAB Management Commands/Functions Other Useful MATLAB Management Commands/Functions demo - Run demos demo - Run demos help- Online help help- Online help ver- Current MATLAB and toolbox versions ver- Current MATLAB and toolbox versions version - Current MATLAB version number version - Current MATLAB version number path- MATLAB Search path path- MATLAB Search path diary - Save typed commands on a named file diary - Save typed commands on a named file

31
January 24, 2005 Lecture 3 - By P. Lin 31 Summary Desktop Tools Desktop Tools Starting and Quitting MATLAB Starting and Quitting MATLAB Command Window Command Window Running FunctionsRunning Functions Entering VariablesEntering Variables Controlling Input/OutputControlling Input/Output Searching ItemsSearching Items Running ProgramsRunning Programs Preferences for the Command WindowPreferences for the Command Window Command History Command History The MATLAB Workspace The MATLAB Workspace Help Browser Help Browser Workspace Browser Workspace Browser Current Directory Browser Current Directory Browser Edit/Debug - a sine wave program Edit/Debug - a sine wave program

32
January 24, 2005 Lecture 3 - By P. Lin 32 Question? Answers Email: lin@ipfw.edu

Similar presentations

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google