Matlab Imp Intro
Matlab Imp Intro
Introduction
Types of Function
Sharing Data using Global memory
Preserving data between calls to a function
String Function
INTRODUCTION
Simulink is a MATLAB-based graphical programming
environment for modeling, simulating and analyzing multi
domain dynamical systems. Its primary interface is a
graphical block diagramming tool and a customizable set of
block libraries.
Developer: MathWorks
License: Proprietary
Operating system: Linux, macOS, Microsoft Windows
OTHER FEATURES
Simulink includes a comprehensive block library of sinks, sources, linear and
nonlinear components, and connectors.
Control Systems
Signal Processing Systems
Video Processing Systems
Image Processing Systems
Communication
Satellite Systems
Ship Systems
Automotive Systems
Monetary Systems
STARTING SIMULINK
Simulink is started from the MATLAB command prompt by entering the following command:
simulink
Alternatively, you can hit the Simulink button at the top of the MATLAB window as shown here:
STARTING SIMULINK
Once you click on Blank Model, a new window will appear as shown below.
STARTING SIMULINK
When it starts, Simulink brings up a single window, entitled Simulink Start Page which can be seen here.
MATLAB SIMULINK - BLOCKS
Blocks in Simulink helps to create models. You can make use of a
Simulink library browser that has different types of blocks for
creating a model.
Signal Amplification
To create a simple model of Gain Amplifier,
You can varry the gain and sine wave amplitude as per your requirement
SIMULATION (INPUT + OUTPUT)
You can vary the gain and sine wave amplitude as per your requirement
PLOTTING IN DIFFERENT SECTION
SIMULATION (BY MUX)
You can vary the gain and sine wave amplitude as per your requirement
CREATING MODEL ANNOTATION & SIGNAL LABELING
Click on
Viewers Manager
SCOPE MANAGER
Add number of
viewer
Viewer’s Point
are Created
FLOATING SCOPE
The Floating Scope is a sink block from the Simulink/Sinks library in the Simulink Library
Browser. This block is similar to the Scope block, but it does not have any input ports! Instead, you
can select any signals in your model and view them on the Floating Scope.
a=out.tout;
% under out we need tout values
b=out.simout.signals.values
% under out > simout > signals > values
% TO ACCUMULATE ALL VARIABLE IN % TO SAVE IN EXCEL FOTMATE
SINGLE EXCEL SHEET % first change the location where you want
a=out.tout; to save the excel sheet
b=out.simout.signals.values;
c=[a b] xlswrite('my data',c)
ANSWER
c =
0 0 0
0.2000 3.9734 1.9867
0.4000 7.7884 3.8942
0.6000 11.2928 5.6464
0.8000 14.3471 7.1736
1.0000 16.8294 8.4147
1.2000 18.6408 9.3204
1.4000 19.7090 9.8545
1.6000 19.9915 9.9957
1.8000 19.4770 9.7385
2.0000 18.1859 9.0930
…. … …
COLLECT DATA FROM SCOPE AND SAVE IT IN EXCEL
DATA IMPORTING FROM EXCEL SHEET
d=xlsread('my data');
% Read your excel sheet & save it to a variable.
DATA IMPORTING FROM EXCEL SHEET
SIGNAL ROUTING (BUS CREATOR/BUS SELECTOR)
When you have numbers of block are more , it’s very difficult to routing the signal.
So we use these two option to minimize the connection between two or numvbers
For Example : blocks
SIGNAL ROUTING (BUS CREATOR/BUS SELECTOR)
The Bus Creator block combines a set of signals into a bus, i.e., a group of signals represented by a
single line in a block diagram.
The Bus Selector block accepts input from a Bus Creator block or another Bus Selector block. This
block has one input port. The number of output ports depends on the state of the Muxed output check
box.
SIGNAL ROUTING (BUS CREATOR)
Subsystems are useful when your model gets big and complex. You
can change a part of the model into a subsystem that helps to keep
the flow very clean and understandable.
Let us add one more block named Unary minus that will
change the output from 30 to -30
CREATING SUB SYSTEM IN SIMULINK
Now, let us select the portion i.e. the sum and the Unary
minus block to create a subsystem
Steps:
1. Save the model.
2. Close the model
3. Reopen the model again
4. Do the setting in
MODELLING > Model Settings > Model Properties > Callbacks > PreLoadFcn > Assign the value
USE OF MATLAB INBUILT FUNCTION IN SIMULINK
Steps:
1. Drag & Drop Matlab Function
2. Double click on that block
3. In command prompt its create a function file
4. Modified the function as per your requirement.
USER DEFINE FUNCTION (MATLAB FUNCTION)
Steps:
1. Drag & Drop Matlab Function
2. Double click on that block
3. In command prompt its create a function file Example we want to check:
4. Modified the function as per your requirement. function distance = dist2(x1,y1,x2,y2)
5. Automatically the function input change as per function % distance between two points
% syntax: distance=dist2(x1,y1,x2,y2)
distance=sqrt((x2-x1)^2+(y2-y1)^2);
USER DEFINE FUNCTION (MATLAB FUNCTION)
SOLVER BLOCK
MATH OPERATION
SIMULINK
MATH OPERATIONS
86+24/(14-2)
Answer : 88
Answer : 2
SOLUTION
EXAMPLE
y(t) = 2Sin(t) + 5Sin(2t) - 10
Following are the steps to solve the equation −
Get a Sine wave block. Right click and select block parameters. Select sign type as time based. Change
the amplitude to 2 and frequency to 1. That will be 2Sin(t).
Get another sine wave block. Now, set the amplitude to 5 and frequency to 2 to display 5Sin(2t). Select
sign type as time based.
Now get an add block and add both sine waves.
Get a constant. Right click and select block parameters. Change the value from 1 to 10.
Get a subtract block where one input will come from step 3 and another from constant i.e. step 4.
Get a scope block and connect the input from step 6 to it.
EXAMPLE
y(t) = 2Sin(t) + 5Sin(2t) - 10
Voltage-220v ac
Frequency-50Hz
Sample time
GENERATE THREE PHASE SUPPLY WAVE FORM
angle u
Specify the angle, in degrees, of the three-phase output
signal.
Freq
Specify the frequency, in hertz, of the three-phase
output signal.
abc
Returns the three-phase signal.
wt
Angle (rad) varying between 0 and 2*pi, synchronized on
zero crossings of the fundamental (positive-sequence) of
phase A.
GENERATE THREE PHASE SUPPLY WAVE FORM
DC MOTOR
SERIES,SHUNT,COMOPOUND