-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForbesanalysis.m
More file actions
129 lines (113 loc) · 3.78 KB
/
Forbesanalysis.m
File metadata and controls
129 lines (113 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
%%
%%MATLABFinalProject
%% Url: www.Forbes.com
%% << Alex Vizhalil >>
%% U. of Illinois, Chicago
%% CS109, Fall 2015
%% Final Project
function Forbesanalysis(filename, filename2)
fprintf('** The Forbes Top 50 Ranking of the Worlds Biggest Companies (Year 2014) **\n');
fprintf('\n');
data = dataset('XLSFile', filename,'ReadVarNames', true);
data2 = dataset('XLSFile', filename2,'ReadVarNames', true);
operation = menu('Please select an operation:' ,'Graph Country Pie Chart' ,'Industry Vs Total Values', 'Plot individual company values');
if operation == 1
PlotPieChart(data, data2);
elseif operation == 2
PlotIndustryVSValue(data);
elseif operation == 3
PlotCompanyvalues(data);
else
fprintf('**Error, unknown operation\n');
end
fprintf('\n');
end
function PlotPieChart(data, data2)
[XNames i j]=unique(data2.country);
XPercentage=histc(j,1:length(XNames));
X1 = flipud( XPercentage);
X2 = flipud( XNames);
[YNames x y]=unique(data.Country);
YPercentage=histc(y,1:length(YNames));
Y1 = flipud( YPercentage);
Y2 = flipud( YNames);
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
pie(ax1,X1);
legend(ax1,X2);
pie(ax2,Y1);
legend(ax2,Y2);
title(ax1,'Percentage of Top 50 Companies per Country for 2004');
title(ax2,'Percentage of Top 50 Companies per Country for 2014');
end
function PlotIndustryVSValue(data)
[x]=unique(data.Industry);
for i = [1:19]
LI = strcmp(data.Industry, x(i)) == 1;
total = data(LI, :);
marketvalue1(i) = sum(total.Market_Value);
sales1(i) = sum(total.Sales);
profits1(i) = sum(total.Profits);
end
Y = cat(1, marketvalue1,sales1,profits1);
bar3(Y)
title('Industries vs total Market Value, Sales, and Profits','FontWeight','bold','FontSize',24)
zlabel('Amount in Billions (USD)')
label = strvcat('Market Value', 'Sales', 'Profits');
set(gca,'XTickLabel',x);
ax.XTickLabelRotation = -45;
set(gca,'YTickLabel',label);
set(gca,'xtick',1:19);
set(gca,'ytick',[1:3]);
set(gca,'ztick',[0:500:3000]);
end
function PlotCompanyvalues(data)
A = data.Rank;
B = data.Company;
C={[num2str(A) repmat(' ',size(A,1),1) char(B)]};
C{:}
a= inputdlg('Select the rank of the first company between 1 and 50','26',1);
x=str2num(a{1});
b= inputdlg('Select the rank of the second company between 1 and 50','28',1);
y=str2num(b{1});
company = data.Company(x);
company2 = data.Company(y);
LI = strcmp(data.Company, company ) == 1;
LI2 = strcmp(data.Company, company2 ) == 1;
List = data(LI, :)
List2 = data(LI2, :)
marketvalue = List.Market_Value;
sales = List.Sales;
profits = List.Profits;
assets = List.Assets;
marketvalue2 = List2.Market_Value;
sales2 = List2.Sales;
profits2 = List2.Profits;
assets2 = List2.Assets;
s1 = List.Company;
s2 = List2.Company;
s3 =char(s1);
s4 =char(s2);
Y = cat(1, marketvalue,sales,profits,assets);
Y2 = cat(1, marketvalue2,sales2,profits2,assets2);
xlab = 'Financial Values of ';
str1 =sprintf('%s',xlab,s3);
str2 =sprintf('%s',xlab,s4);
figure
subplot(2,1,1);
bar(Y,'r')
legend(List.Company)
xlabel(str1);
ylabel('Amount in Billions (USD)')
label = strvcat('Market Value', 'Sales', 'Profits', 'Assets');
set(gca,'XTickLabel',label)
title('Comparison Between Two Companies')
subplot(2,1,2);
bar(Y2,'b')
legend(List2.Company)
xlabel(str2);
ylabel('Amount in Billions (USD)')
label = strvcat('Market Value', 'Sales', 'Profits', 'Assets');
set(gca,'XTickLabel',label)
title('Comparison Between Two Companies')
end