# Matlab Plot - stem

In this example, we study the 'stem' instruction to plot Matlab functions.

It draws vertical lines (with a little circle at the tip) proportional to the value of the function at that particular horizontal value. 'stem' does not join the circles with a line, and it is very helpful to stress the fact that the function is not continuous but discrete.

Let's assume that we want to plot the following elegant exponential and sinusoidal function:

### Example: let's draw a simple discrete function

We can develop a script like this:

% Avoid superimposed operations and close previous figs.
clc; clear; close all

% First, we define 51 values of our independent variable
x = 0 : 2*pi/50 : 2*pi;

% Second, we define the function to graph
y = exp(-x/3) .* sin(x);

% Third, we use the 'stem' function to plot discrete values
stem(x,y)

% We can add title and labels (as strings in arguments)
title('Demonstration of the -stem- function')
xlabel(
'angle x')
ylabel(
'f(x)')

And we get the following plot:

If we define our independant variable using less points, as in

x = 0 : 2*pi/20 : 2*pi;

we get the following visual change:

From 'Matlab Plot' to home

From 'Matlab Plot' to '2D Plot Menu'

 Top Horizontal and Vertical lines Different 2D Graphs

## Related pages

matlab plot 2d matrix1089 math trickgeneric programingmatlab stop programquadratic equation c programming codealphabet in asciibuilt in functions matlabmaclaurin series calculator onlinegraph a piecewise functionfibonacci for loophex to decimal algorithmplotting polynomials in matlabprobability binomial distribution calculatorexamples of fibonaccibinary to hexadecimal tabledefining a function in matlab3n 1 sequencehow to solve smith chart problemsmatlab fft helpsimpson method integrationcalculator integralsonline ohms law calculatoradmittance smith chartbins matlabbin to decimalhow to find roots of quadratic equationcall function in matlabtaylor series calculator onlinesimple matlab gui exampleshow to draw graph in matlabconversion to binary numberstransient rc circuit analysisadmittance smith chartpolyfit matlabmatlab plot step functionmatlab inverthow to learn matlabloan repayment equationscilab programmatlab tutorialplot square matlabplot gaussian matlabmatlab calculatormatlab interp1maclaurin series definitionfind integral calculatorrc circuit voltage across capacitorcurve fitting matlab commandoctet to decimalinfinite geometric series sum formulamatlab plot log scaledefine salvage valuemaclauren seriesgraph of a piecewise functionbuilt in functions matlabmatlab solving systems of equationszy smith chart color pdfcontinuously compounded interest equationlinear regression matlab codebinary and hexadecimal numbersfor loop in matlab exampleascii code of lettersmatlab fprintf tablerecursion programhow to get the salvage valuepascal triangleequation solver matlabzy smith chart color pdfsum of fibonacci seriesgold band on resistorelectricity cost calculator wattsproject in matlab with codingwhile loop in matlab examplesbmi index tablematlab loops exampleskcl equationrc transient circuitconverting gray code to binary