Digital Signal Processing Reference
In-Depth Information
Test plots of sinusoids
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time (sec.)
FIGURE A.2
Illustration of MATLAB script file test.m.
xlabel(
'
Time (sec.)
'
); hold on
plot(t,y,
-.
);
'
'
A.5 MATLAB FUNCTIONS
A MATLAB function is often used to replace the repetitive portions of MATLAB code. It is
created using a MATLAB script file. However, the code begins with the keyword function,
followed by the function declaration, comments for the help system, and program code.
A function sumsub.m that computes the addition and subtraction of two numbers is listed here
for illustration.
sumsub.m
function [sum, sub] ¼ sumsub(x1,x2)
%sumsub: Function to add and subtract two numbers
% Usage:
% [sum, sub] ¼ sumsub(x1,x2)
%x1 ¼ the first number
%x2 ¼ the second number
% sum ¼ x1+x2;
 
Search WWH ::




Custom Search