As with bar graphs, line graphs are easy to make in MATLAB. Let's start this tutorial by loading some data to play with. The file you need is HERE. Download it now and place it in your MATLAB/Tutorial directory.
Let's clear everything we have so far.
clc;
clear all;
close all;
Now, load the data.
load('sampleLineData');
This command will load the file and you will see a variable called lineData in your Workspace. The data has three rows. The first just identifies 7 measurement points. The second reflect incomes at these measurement points. The last row reflects the variability in the measurement at each point (the error).
Plotting this is easy:
plot(lineData(1,:),lineData(2,:));
You will see a simple line graph that is easily customizable like the previous bar plot. For instance, try this command now.
plot(lineData(1,:),lineData(2,:),'b--o','LineWidth',2,'MarkerSize',10);
As I stated before, there are a myriad of ways to customize plots in MATLAB.
Error Bars
If you want error bars, it is actually very easy for a line plot at this is the default setting for errorbar. Try this:
errorbar(lineData(1,:),lineData(2,:),lineData(3,:));
You see? Anything can be done. Speaking of which...
The MATLAB Central File Exchange
One of the advantages to MATLAB is that there is a huge file repository of projects people have posted online that you can download for free. The repository is HERE, but you need to create an account to join (it's free!), but in the interests of time download this FILE and put in in your MATLAB path. It is a file I have downloaded for you from the file repository. Then, try this:
shadedbar(lineData(1,:),lineData(2,:),lineData(3,:));
You should see a line graph with a shaded error bar interval. Again, anything can be done!
Things To Do
1. Again, try customizing these plots. Think of something you want to change, and try and change it. For example. on the last plot label the title, axes, etc. Change colours, be creative!
Then, on to the next tutorial!
Let's clear everything we have so far.
clc;
clear all;
close all;
Now, load the data.
load('sampleLineData');
This command will load the file and you will see a variable called lineData in your Workspace. The data has three rows. The first just identifies 7 measurement points. The second reflect incomes at these measurement points. The last row reflects the variability in the measurement at each point (the error).
Plotting this is easy:
plot(lineData(1,:),lineData(2,:));
You will see a simple line graph that is easily customizable like the previous bar plot. For instance, try this command now.
plot(lineData(1,:),lineData(2,:),'b--o','LineWidth',2,'MarkerSize',10);
As I stated before, there are a myriad of ways to customize plots in MATLAB.
Error Bars
If you want error bars, it is actually very easy for a line plot at this is the default setting for errorbar. Try this:
errorbar(lineData(1,:),lineData(2,:),lineData(3,:));
You see? Anything can be done. Speaking of which...
The MATLAB Central File Exchange
One of the advantages to MATLAB is that there is a huge file repository of projects people have posted online that you can download for free. The repository is HERE, but you need to create an account to join (it's free!), but in the interests of time download this FILE and put in in your MATLAB path. It is a file I have downloaded for you from the file repository. Then, try this:
shadedbar(lineData(1,:),lineData(2,:),lineData(3,:));
You should see a line graph with a shaded error bar interval. Again, anything can be done!
Things To Do
1. Again, try customizing these plots. Think of something you want to change, and try and change it. For example. on the last plot label the title, axes, etc. Change colours, be creative!
Then, on to the next tutorial!