Importing countries and years data into MATLAB

4 views (last 30 days)
I am new to the whole matlab environment so i was hoping someone is able to guide me along. The project i am doing is environment related, i have data of various countries as well as the energy consumption, forest area and carbon emission. They are labeled as (E1990, F1990, C1990).
I have the following code to sort them in various years making it easier to call them out when plotting various graphs. However i am thinking of sorting them by countries.
Energy = FullDataset(1:60,:);
D1990 = Energy(:, { 'Country' 'E1990' 'C1990' 'F1990' 'P1990'});
D1991 = Energy(:, { 'Country' 'E1991' 'C1991' 'F1991' 'P1991'});
D1992 = Energy(:, { 'Country' 'E1992' 'C1992' 'F1992' 'P1992'});
D1993 = Energy(:, { 'Country' 'E1993' 'C1993' 'F1993' 'P1993'});
Example: Plot (Australia E1990, Canada E1990) or Plot (Australia , Canada) // this is suppose to show data ranging from E1990 - E1997 for Australia against Canada.
Secondly, I am seeking recommendation for the type of graph i should be using. Given that my data set consist of Energy consumption, forest area, carbon emission, population, earth average temperature.
Would really appreciate any comments or help given.
Cheers

Accepted Answer

Image Analyst
Image Analyst on 11 Apr 2014
Edited: Image Analyst on 11 Apr 2014
Attach the data file. This can probably be done very easily with the new "table" data type.
% Example using patients demo table.
load patients
patients = table(Age,Gender,Height,Weight,Smoker,...
'RowNames',LastName)
t = patients([2,4], [1, 3,4])
xData = t{1,:}
yData = t{2,:}
scatter(xData, yData);
Requires R2013b or later.
  2 Comments
Tze Tian
Tze Tian on 11 Apr 2014
Thank you very much. Guess i will just have to import the data separately to work. By the way just another 2 short question.
What does this command does ? xData = t{1,:}
And also what sort of graph do you recommend for my case. Should i be throwing all data set together to compare ? or should i plot a graph with multiple lines representing the different countries for each data ?
Sorry if it is confusing as i am quite indecisive as to what sort of comparison or visualization should i do for the best representation of environmental impact.
Image Analyst
Image Analyst on 11 Apr 2014
Why do you have to import separately? Can't you just do
originalTable = readtable(yourDataFileName);
??? It imports the whole table in just one line. There are probably multiple ways to display this. Perhaps a set of colored bars in a chart might be the best way - depends on how you want to present it. Maybe have the year be the "X" axis and the value on the Y and at each year you have a set of 10 or however many countries. You can use bar() with a 2D array to plot it like that.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!