Introduction To Matlab PDF
Introduction To Matlab PDF
% This is a comment,
y = 5*3 + 2^2;
x = [1 2 4 5 6];
x1 = x.^2;
E = sum(abs(x).^2);
P = E/length(x);
x2 = x(1:3);
z = 1+i;
a = real(z);
b = imag(z);
plot(x);
t = 0:0.1:100;
x3=exp(-t).*cos(t);
plot(t, x3, x);
it starts with a %
% simple arithmetic
% create the vector x
% square each element in x
% Calculate signal energy
% Calculate av signal power
% Select first 3 elements in x
% Create a complex number
% Pick off real part
% Pick off imaginary part
% Plot the vector as a signal
% Generate sampled time
% Generate a discrete signal
% Plot points
Decisions
for i=1:100
sum = sum+i;
end
Goes round the for loop 100
times, starting at i=1 and
finishing at i=100
if i==5
a = i*2;
else
a = i*4;
end
Executes whichever branch is
appropriate depending on test
i=1;
while i<=100
sum = sum+i;
i = i+1;
end
Similar, but uses a while loop
instead of a for loop
switch i
case 5
a = i*2;
otherwise
a = i*4;
end
Similar, but uses a switch
Matlab Help!
These slides have provided a rapid introduction to Matlab
Mastering Matlab 6, Prentice Hall,
Introduction to Matlab (on-line)
Lots of help available
Type help in the command window or help operator. This
displays the help associated with the specified operator/function
Type lookfor topic to search for Matlab commands that are
related to the specified topic
Type helpdesk in the command window or select help on the pull
down menu. This allows you to access several, well-written
programming tutorials.
comp.soft-sys.matlab newsgroup
Introduction to Simulink
Simulink is a graphical, drag and drop environment for
building simple and complex signal and system
dynamic simulations.
It allows users to concentrate on the structure of the
problem, rather than having to worry (too much)
about a programming language.
The parameters of each signal and system block is
configured by the user (right click on block)
Signals and systems are simulated over a particular
time.
Signals in Simulink
Two main libraries for manipulating signals in
Simulink:
Sources: generate a signal
Sink: display, read or store a signal
Lecture 2: Summary
This lecture has looked at signals:
Power and energy
Signal transformations
Time shift
Periodic
Even and odd signals
Lecture 2: Exercises
SaS OW:
Q1.3
Q1.7-1.14
Matlab/Simulink
Try out basic Matlab commands on slide 17
Try creating the sin/scope Simulink simulation on slide
23 and modify the parameters of the sine wave and rerun the simulation
Learning how to use the help facilities in Matlab is
important - do it!