Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB-Plot two sets of data on the same graph with custom increments

  1. Nov 19, 2013 #1
    Hi, I was trying to plot two sets of data on the same graph and this was my solution but this generates a graph with the x-axis in 0.5 increments where I wanted 1. How do I plot two sets of data on the same graph and customize the increments. Thanks in advance. Also, how would I make matlab calculate the area under each curve?
    Code (Text):
    x = [1 2 3 4 5];

    y2 =[84,86,84,81,84,];

    plot(x, [y(:) y2(:)])

  2. jcsd
  3. Nov 20, 2013 #2


    User Avatar
    Gold Member

    In general you plot multiple things in the same figure window by using the "hold on" command. This keeps the current figure open and active for future plot commands (it plots overtop of whats already there). When you need a new figure, just type "hold off" and new plots will be done in a new window.

    This page explains how to set the axis limits and tick intervals.

    Since you have discrete data, use the trapz(x,y) or cumtrapz(x,y) functions to calculate the area under each curve. The difference between the two is that trapz() just gives you the final area, whereas cumtrapz gives you the intermediate values as well.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - MATLAB Plot sets Date
Matlab Plotting Coordinate Transformations in Matlab Feb 12, 2018
Matlab Plotting animations (time-evolution) Jan 17, 2018
Does anyone had this plotting problem with MATLAB? Dec 23, 2017
Matlab Matlab's plot command Nov 30, 2017
Matlab How to set zero value boxes transparent in 3D plots? May 17, 2016