-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDF_MakeLegend.m
39 lines (36 loc) · 1.28 KB
/
DF_MakeLegend.m
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
function legendcell = DF_MakeLegend(bins)
% a function to easily spit out a legend based on the bins
legendcell = {};
n_bins = max(size(bins));
bins = bins * 100; % convert to percent
% negative bins
if bins(1) < 0 && bins(end) == 0
for i = n_bins:-1:1 % these go BACKWARDS because of how 'area' arranges the values
if i == 1
legendcell(end + 1) = cellstr(['<' num2str(bins(i)) '%']);
else
legendcell(end + 1) = cellstr([num2str(bins(i)) '% to ' num2str(bins(i-1)) '%' ]);
end
end
% positive bins
elseif bins(1) == 0 && bins(end) > 0
for i = 1:n_bins
if i == n_bins
legendcell(end + 1) = cellstr(['>' num2str(bins(end)) '%']);
else
legendcell(end + 1) = cellstr([num2str(bins(i)) '% to ' num2str(bins(i + 1)) '%']);
end
end
% mixed bins
else
for i = 1:n_bins + 1
if i == 1
legendcell(end + 1) = cellstr(['<' num2str(bins(i)) '%']);
elseif i == n_bins + 1
legendcell(end + 1) = cellstr(['>' num2str(bins(end)) '%']);
else
legendcell(end + 1) = cellstr([num2str(bins(i-1)) '% to ' num2str(bins(i)) '%']);
end
end
end
%assignin('base', 'legendcell', legendcell);