如何从matlab

时间:2017-05-07 00:41:39

标签: matlab matlab-figure

我想在MATLAB中绘制一个条形图,代表玩家与赢得的年数。例如,

______________________________________
Country         Years won
______________________________________
US           2012, 2013
Canada        2012, 2013, 2017
Belgium      2002, 2004,2013, 2017
Hungary      2001, 2002, 2014, 2014

如何在MATLAB中绘制此数据值的条形图?我想知道是否有人可以帮助我?

1 个答案:

答案 0 :(得分:1)

如果您想绘制每个国家/地区胜利的数字的条形图,您可以执行以下操作:

% country names cell array
Names = {'US','Canada','Belgium','Hungary'};
% years won cell array
YearsWon = {[2012, 2013],[2012, 2013, 2017],...
    [2002, 2004,2013, 2017],[2001, 2002, 2014, 2014]};
% number of years won
nWins = cellfun(@numel,YearsWon);
% bar plot
bar(nWins);
% set x&y tick labels
set(gca, 'XTickLabel', Names, 'XTickLabelRotation', -45,...
    'YTick', 0:max(nWins));
% set x&y axes labels
xlabel('Country Name'); ylabel('Years Won')

enter image description here