Professional Documents
Culture Documents
Objectives/lab goals:
Learning major command such as:
1. Generating Functions
2. Simulink
Functions:
A function is a group of statements that together perform a task. In MATLAB, functions are defined in
separate files. The name of the file and of the function should be the same.
Functions can accept more than one input arguments and may return more than one output arguments.
Syntax of a function statement is −
function [out1,out2, ..., outN] = myfun(in1,in2,in3, ..., inN)
Example
1. The following function named mymaxnum should be written in a file named mymaxnum.m. It
takes five numbers as argument and returns the maximum of the numbers.
2. Create a function file, named mymaxnum.m and type the following code in it.
3. Command function [] is used to generate the new function named as “mymaxnum”.
4. Then if else are used for conditioning.
5. This will return the number which is largest.
Figure 2: Example of defining new function as in this case mymaxnum is a new function introduced in matlab
>> simulink
The alternate method is to click the Simulink icon in the MATLAB toolbar
Figure 3: accessing simulink through matlab
The Library Browser contains various toolboxes in left side and corresponding utilities and blocks on
the right side.
Creating a model:
To start creating a model go to File –> New or alternatively Ctrl+N. A Work space / Model window will
pop up as shown below:
It will take a few moments for the first time running on laptop.
Figure 5: simulink window
Here create a simple model of integrating a sine wave and display both the input sine wave and the
integral form. To create this model, required is
Charting down all the needed components is good practice when it comes to designing of higher models.
STEP 1:
Selecting Blocks
For a sine wave sources