Digital Signal Processing Reference
In-Depth Information
function [f1] = myfirstplot(k)
% USAGE: [f1] = myfirstplot(k)
% Plots f1 = sin(0.1*pi*k) as a function of k in subplot
% (2,2,1) where k = row vector containing the indices
% where f1 is to be defined f1 is the output row vector
figure(5) % Select figure 5 for plots
clf % Clear figure 5
f1 = sin(0.1*pi*k); % Calculate function f1
subplot(2,2,1);
% Divides fig 5 into (m = 2) vertical
% and (n = 2) horizontal sub-figures
% The last argument (p = 1) accesses
% sub-figures. (1 <= p <= m*n)
stem(k,f1,'filled');
grid on;
% DT plot of f1 versus k
xlabel('k') ;
% Label of X-axis
ylabel('f1[k]')
% Label of Y-axis
end
Once a function has been created, it must be saved in a file whose name is
same as the defined name of the function. In our example, the aforementioned
function must be saved in a file myfirstplot.m . The calling format for a
function is the same as one would use to access a M ATLAB built-in function.
To access myfirstplot , the following instructions must be typed at the
M ATLAB prompt:
>> m = [-5:5]; % Define the input argument
>> [y] = myfirstplot(m); % Output value is returned to y
% with subplot plotted in
% figure 5
E.7 Summary
In this appendix, a working introduction to M ATLAB is provided. The intent
is to introduce the basic capabilities of M ATLAB to the reader. M ATLAB
supports hundreds of built-in functions from linear algebra, numerical analysis,
polynomial algebra, and numerical optimization. These built-in functions are
supported in both the student and full version of M ATLAB , and do not require
any toolboxes. A list of built-in functions is available on the Mathworks website
(www.mathworks.com). Readers are encouraged to visit the website and explore
M ATLAB in more detail.
Search WWH ::




Custom Search