Tag Archives: plot

A easy way to plot a equation using MATLAB.’syms’

It is quite often required to plot a function like ” Gaussian distribution, a*exp(-(x-b)^2/2c) or f=x^2″


MATLAB has the function to plot and manipulate symbolic equations in a easy way.


For example, if I want to plot y=x^2+3.

syms x;



If you face this error “Single input must be an existing figure handle or a scalar integerfrom 1 to 2147483646″, please check the definition function.

f=x^2+3 and f=’x^2+3′ are different.

Give a try to define your own function and plot it.


Matlab multi line plot in the same window.

There are two common ways to plot more than 2 data on the same window.

The first method uses one line and is of the form plot(xfunction, style#1 ,x, function#2style#2, ). For example,

The second method involves the use of the “hold on” and “hold off” commands. After creating the first graph, use the “hold on” command, forcing subsequent graphing commands to be placed in the same window. Now type in your second plot command. When you are through, type “hold off”. For example

hold on

To add labels to your axes, use the following

xlabel(‘this goes across’)
ylabel(‘this goes up)
hold off