MATLAB: How to plot vertical line from X Axis to values on graph

lineplotverticalxline

Hi,
Ive got a fft plot with values linked by a line however, I would like the values to be plotted as a straight vertical line down to the x axis so that it just shows each frequency. I havent been able to find a possible way of doing this anywhere. Help on how to do this is very much appreciated.

Best Answer

The easiest way to do this is to use the stem function.
Example —
f = 0:0.05:pi; % Create Frequency Vector
A = rand(size(f)); % Create Fourier Transform Amplitude Vector
figure
plot(f, A, '-b')
hold on
stem(f, A, '-r', 'Marker','none') % Plot ‘stem’ Without Markers
hold off
grid
This plots the Fourier transform amplitudes with a blue line, and with red stem lines. Change the various properties to get the result you want.