Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic operations in Matlab

Similar presentations


Presentation on theme: "Basic operations in Matlab"— Presentation transcript:

1 Basic operations in Matlab
EE 201

2 Class Learning Objectives
Achieve Comprehension LOL of Matlab basic operations.

3 Script files You can perform operations in MATLAB in two ways:
1. In the interactive mode (similar to using a calculator), in which all commands are entered directly in the Command window, or 2. By running a MATLAB program stored in script file. This type of file contains MATLAB commands, so running it is equivalent to typing all the commands - one at a time - at the Command window prompt.

4 Script files A script files contain a sequence of MATLAB commands, and is useful when you need to use many commands or arrays with many elements. Script files in MATLAB allows you to write your own programs and save in M-files, which have the extension .m, for example, name of file.m

5 Creating M-file From the File menu →select New →Script
Then will see a new edit window called editor window as shown in figure

6 Keep in mind when using script files:
The name of a script file MUST begin with a letter, and may include digits and the underscore character, up to 31 characters. Do not give a script file the same name as a variable. Do not give a script file the same name as a MATLAB command or function. You can check to see if a command, function or file name already exists by using the exist command.

7 COMMENTS The comment symbol (%) may be put anywhere in the line. MATLAB ignores everything to the right of the % symbol. For example :

8 Programming Style 1.Comments section %
a. The name of the program and any key words in the first line. b. The date created, the student‘s names and ID number in the second line. c. The definitions of the variable names for every input and output variable. Include definitions of variables used in the calculations and units of measurement for all input and all output variables! d. The name of every user-defined function called by the program.

9 Programming Style 2. Input section :
Include input data and/or the input functions and comments for documentation. 3. Calculation section 4.Output section This section might contain functions for displaying the output on the screen.

10 Examples of a Script File
Write a MATALB program that inputs three integers from the keyboard and prints the sum,average,and product of these numbers. The screen dialogue should appear as follows: The first integer is : 13 The second integer is :27 The third integer is :14 Sum is: 54 Average is:18 Product is :4914

11

12

13 You can execute a script file by :
-Go to Debug menu →Run or -Press F5 -Typing the name of script file without the extension .m at the command window

14 Example of script file Write a MATLAB program that compute the volume of sphere with a radius 3 cm.

15

16 Example of script file Write a MATLAB program that prompts the user to enter a radius (cm) of sphere to compute the volume of sphere.

17


Download ppt "Basic operations in Matlab"

Similar presentations


Ads by Google