Matlab - plotting a function waveform, line and stem

Опубликовано: 03 Июль 2026
на канале: Alan Wood
1,904
9

Plotting a function by cut-and-pasting an example from the technical help web site.

Here's the code:
% Plotting a waveform with a line and stems example, A.W. Dec 2012
x=0:0.05:2; % make an x range from 0 to 2, with 1/20 steps
y=sqrt(x).*sin(2*pi*x); % make y be some function of x

figure % (optional) make a new plot window
plot(x,y,'g') % plot y against x with a green line
title('Modulated Sine Wave Plot');

hold on % keep the existing curve(s)
stem(x,y,'r') % plot stems in red

ylabel('Amplitude') % axis labels
xlabel('Time')
axis([0,2,-2,2]) % set axes range x=0 - 2, y=-2 - +2
hold off