# Plotting in matlab

 Page 1 / 2
Plotting basics.

A picture is worth a thousand words, particularly visual representation of data in engineering is very useful. MATLAB has powerful graphics tools and there is a very helpful section devoted to graphics in MATLAB Help: Graphics. Students are encouraged to study that section; what follows is a brief summary of the main plotting features.

## The `plot` Statement

Probably the most common method for creating a plot is by issuing `plot(x, y)` statement where function y is plotted against x.

Type in the following statement at the MATLAB prompt:

`x=[-pi:.1:pi]; y=sin(x); plot(x,y);`

After we executed the statement above, a plot named Figure1 is generated:

Having variables assigned in the Workspace, x and y=sin(x) in our case, we can also select x and y, and right click on the selected variables. This opens a menu from which we choose plot(x,y). See the figure below.

## Annotating plots

Graphs without labels are incomplete and labeling elements such as plot title, labels for x and y axes, and legend should be included. Using up arrow, recall the statement above and add the annotation commands as shown below.

`x=[-pi:.1:pi];y=sin(x);plot(x,y);title('Graph of y=sin(x)');xlabel('x');ylabel('sin(x)');grid on`

Run the file and compare your result with the first one.

Type in the following at the MATLAB prompt and learn additional commands to annotate plots: ```help gtext help legendhelp zlabel```

## Superimposed plots

If you want to merge data from two graphs, rather than create a new graph from scratch, you can superimpose the two using a simple trick:

```% This script generates sin(x) and cos(x) plot on the same graph % initialize variablesx=[-pi:.1:pi]; %create a row vector from -pi to +pi with .1 incrementsy0=sin(x); %calculate sine value for each x y1=cos(x); %calculate cosine value for each x% Plot sin(x) and cos(x) on the same graph plot(x,y0,x,y1);title('Graph of sin(x) and cos(x)'); %Title of graph xlabel('x'); %Label of x axisylabel('sin(x), cos(x)'); %Label of y axis legend('sin(x)','cos(x)'); %Insert legend in the same order as y0 and y1 calculatedgrid on %Graph grid is turned```

## Multiple plots in a figure

Multiple plots in a single figure can be generated with `subplot` in the Command Window. However, this time we will use the built-in Plot Tools. Before we initialize that tool set, let us create the necessary variables using the following script:

```% This script generates sin(x) and cos(x) variables clc %Clears command windowclear all %Clears the variable space close all %Closes all figuresX1=[-2*pi:.1:2*pi]; %Creates a row vector from -2*pi to 2*pi with .1 incrementsY1=sin(X1); %Calculates sine value for each x Y2=cos(X1); %Calculates cosine value for each xY3=Y1+Y2; %Calculates sin(x)+cos(x) Y4=Y1-Y2; %Calculates sin(x)-cos(x)```

are nano particles real
yeah
Joseph
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
no can't
Lohitha
where we get a research paper on Nano chemistry....?
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
what are the products of Nano chemistry?
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
hey
Giriraj
Preparation and Applications of Nanomaterial for Drug Delivery
revolt
da
Application of nanotechnology in medicine
has a lot of application modern world
Kamaluddeen
yes
narayan
what is variations in raman spectra for nanomaterials
ya I also want to know the raman spectra
Bhagvanji
I only see partial conversation and what's the question here!
what about nanotechnology for water purification
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
what king of growth are you checking .?
Renato
how did you get the value of 2000N.What calculations are needed to arrive at it
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!