How to Plot a Graph in MATLAB

Many times you need to plot data set in the form of graph. Plotting graph is a fun part. Today you’ll learn to plot graph in MATLAB. It is damn easy and takes less than 2 minutes. Let’s start it.

Code to plot graph in MATLAB

Let’s consider have two dimensional data set where equipment sales are plotted against days of week. Let’s say on day 1, the sales are 4.4 lakh, for day 2 4.5 lakh and so on:
Simply these three lines of code in M-file are enough to plot the table in MATLAB:
x = [1 2 3 4 5 6];
y = [4.4 4.5 5.7 6.3 6.9 8.2];
plot (x,y)
And the output is:

how-to-plot-graph-in-matlab
Congrats you plot a graph in MATLAB. But there are few visual problems. There are no lables, one can’t understand what this data set represents. Let’s improve our graph.

x = [1 2 3 4 5 6];
y = [4.4 4.5 5.7 6.3 6.9 8.2];
plot (x,y)
xlabel(‘Days’)
ylabel(‘Sales price in lakh’)
title(‘Sales graph per day’)

And the output will be:

how-to-plot-graph-in-matlab-2
The video below illustrates some useful data plotting tips you might be interested.
You might be interested in:

  1. Free Power Electronics Simulator

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: