What is difference between stem and plot in MATLAB?



Both plot and stem functions are used to represent a curve in MATLAB.
The main point of difference between the two is that plot displays the continuous values for the curve. Think about drawing a graph of y= sin(x) using a pencil without removing its contact from paper.
On the other hand, stem displays the discrete values of the points on the curve. Think about drawing the graph of y=sin(x) for specific values such as 0,15,30,45,60and 90degrees respectively. Then join these points from the X-axis. This is the result given by stem.
Try to run this simple code on MATLAB to find the difference yourself.

clc
clear all
close all
x = linspace(-pi,pi,50);
y = sin(x);
subplot(1,2,1)
plot(x,y)
xticks([ -pi 0 pi ])
xticklabels({'-\pi','0','\pi'})
title('Plot function of Sin(x)')
grid on
subplot(1,2,2)
stem(x,y)
xticks([ -pi 0 pi ])
xticklabels({'-\pi','0','\pi'})
title('Stem function of Sin(x)')
grid on

The output of this code:

In the code, I’ve used linspace to give the range and the division of values. I’ve used subplot to divide the area of of figure window into 2 equal parts. I’ve also used xticks and xticklabels to change the X-axis from number format to π format. I’ve used other features such as title, grid on to make my curve presentable.

You can clearly see that the curve using plot displays a continuous line while the use of stem results in discrete values marked on the graph.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.