0001 function plothist(rank)
0002
0003
0004 [sorted_element, element_count] = countele(rank);
0005
0006
0007
0008 a = 1:length(sorted_element);
0009 bar(a, element_count);
0010 set(gca, 'xticklabel', []);
0011
0012 axis([0 inf 0 inf]);
0013 grid;
0014 xlabel('Ranking'); ylabel('Histogram'); title('Ranking Histogram')
0015
0016
0017
0018 for k = 1:length(sorted_element),
0019 text(k, -1, num2str(sorted_element(k)), 'color', 'black');
0020 end
0021 h = findobj(gcf, 'type', 'text');
0022 set(h, 'rot', 90, 'fontsize', 10, 'hori', 'right');
0023
0024
0025
0026 function [sorted_element, element_count] = countele(in)
0027
0028
0029
0030
0031
0032 if nargin == 0,
0033 in = [0.4 0.3 0.3 0.2 0.1 0.4 0.4 0.3 0.4];
0034 fprintf('The input vector "in" is\n');
0035 for i = 1:length(in),
0036 fprintf('%g ', in(i));
0037 end
0038 fprintf('\n\n"[sorted_element, element_count] = countele(in)" produces the following output:\n');
0039 [sorted_element, element_count] = countele(in)
0040 return;
0041 end
0042
0043 [m,n] = size(in);
0044 in1 = sort(in(:)');
0045 in1 = [in1 in1(length(in1))+1];
0046 index = find(diff(in1) ~= 0);
0047 sorted_element = in1(index);
0048 element_count = diff([0, index]);
0049 if n == 1,
0050 sorted_element = sorted_element';
0051 element_count = element_count';
0052 end