1

您可以忽略程序的前几个部分,因为这只是一个设置,您可以转到它为您提供第一选择的部分。所以我想做的是制作国际足联球队的条形图以及他们拥有的积分数量。数据集是一个 50x9 矩阵。我试图让它绘制第 4 列的所有行(即点数)。但是我一直遇到错误。我从来没有做过条形图,所以我不知道它是如何工作的。我很感激你们能给我的任何意见。

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
4

1 回答 1

1

首先,如果您有 50 个(!)标签要绘制,我会使用barh而不是绘制。bar其次,如果您只需要绘制第 4 列,请使用y= data(:,4);. 例如:

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])

在此处输入图像描述

于 2013-05-07T04:34:44.193 回答