Reputation: 31
You can ignore the first couple parts of the program as this is just a set up, you can go to the part where it gives you the first choice. So what im trying to do is make a bar graph of fifa teams and the amount of points that they have. The dataset is a 50x9 matrix. Im trying to have it graph all the rows (which is the amount of points) of column 4. However I keep experiencing an error. Ive never done bar graphs so I dont know how this work. I appreciate any inputs that you guys could give me.
fprintf('*loading dataset...\n');
fprintf('*analyzing dataset...\n');
data=dataset('File', 'thegrid2.txt', 'Delimiter', ',');
[rows cols] = size(data);
choice= menu('What would you like to see master?:', 'Graph 1', 'Graph 2', 'Graph 3', 'OR Graph 4')
if choice== 1
x= 1:1:50;
y= data(1:rows, cols-5);
bar(x,y)
title([ 'Countries vs. the amount of points: '])
set(gca, 'Xtick', 1:1:50);
set(gca,'XTickLabel', {'ESP','GER','ARG','CRO','POR','COL','ENG','ITA','NED','ECU','RUS','CIV','GRE','MEX','SUI','BEL','URU','FRA','BRA','DEN','BIH','GHA','CHI','SWE','CZE','MLI','MNE','USA','JPN','NOR','NGA','PER','HUN','ROU','ALG','VEN','UKR','PAN','IRL','SRB','TUN','KOR','PAR','TUR','ZAM','AUS','CRC','ALB','WAL','BFA'});
end
Upvotes: 1
Views: 1871
Reputation: 26069
First I'd plot using barh
and not bar
if you have 50 (!) labels to plot.
Second, if you need to plot only the 4th column, use, y= data(:,4);
. For example:
data=rand(50,5);
x= 1:1:50;
y= data(:,4);
barh(x,y)
title([ 'Countries vs. the amount of points: '])
set(gca, 'Ytick', 1:1:50);
set(gca,'YTickLabel', {'ESP','GER','ARG','CRO','POR','COL','ENG','ITA','NED','ECU','RUS','CIV','GRE','MEX','SUI','BEL','URU','FRA','BRA','DEN','BIH','GHA','CHI','SWE','CZE','MLI','MNE','USA','JPN','NOR','NGA','PER','HUN','ROU','ALG','VEN','UKR','PAN','IRL','SRB','TUN','KOR','PAR','TUR','ZAM','AUS','CRC','ALB','WAL','BFA'});
ylim([0 51])
Upvotes: 1