Importing countries and years data into MATLAB
4 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!