-
Notifications
You must be signed in to change notification settings - Fork 0
/
varycolor.m
executable file
·89 lines (74 loc) · 2.4 KB
/
varycolor.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function ColorSet=varycolor(NumberOfPlots)
% VARYCOLOR Produces colors with maximum variation on plots with multiple
% lines.
%
% VARYCOLOR(X) returns a matrix of dimension X by 3. The matrix may be
% used in conjunction with the plot command option 'color' to vary the
% color of lines.
%
% Yellow and White colors were not used because of their poor
% translation to presentations.
%
% Example Usage:
% NumberOfPlots=50;
%
% ColorSet=varycolor(NumberOfPlots);
%
% figure
% hold on;
%
% for m=1:NumberOfPlots
% plot(ones(20,1)*m,'Color',ColorSet(m,:))
% end
%Created by Daniel Helmick 8/12/2008
error(nargchk(1,1,nargin))%correct number of input arguements??
error(nargoutchk(0, 1, nargout))%correct number of output arguements??
%Take care of the anomolies
if NumberOfPlots<1
ColorSet=[];
elseif NumberOfPlots==1
ColorSet=[0 1 0];
elseif NumberOfPlots==2
ColorSet=[0 1 0; 0 1 1];
elseif NumberOfPlots==3
ColorSet=[0 1 0; 0 1 1; 0 0 1];
elseif NumberOfPlots==4
ColorSet=[0 1 0; 0 1 1; 0 0 1; 1 0 1];
elseif NumberOfPlots==5
ColorSet=[0 1 0; 0 1 1; 0 0 1; 1 0 1; 1 0 0];
elseif NumberOfPlots==6
ColorSet=[0 1 0; 0 1 1; 0 0 1; 1 0 1; 1 0 0; 0 0 0];
else %default and where this function has an actual advantage
%we have 5 segments to distribute the plots
EachSec=floor(NumberOfPlots/5);
%how many extra lines are there?
ExtraPlots=mod(NumberOfPlots,5);
%initialize our vector
ColorSet=zeros(NumberOfPlots,3);
%This is to deal with the extra plots that don't fit nicely into the
%segments
Adjust=zeros(1,5);
for m=1:ExtraPlots
Adjust(m)=1;
end
SecOne =EachSec+Adjust(1);
SecTwo =EachSec+Adjust(2);
SecThree =EachSec+Adjust(3);
SecFour =EachSec+Adjust(4);
SecFive =EachSec;
for m=1:SecOne
ColorSet(m,:)=[0 1 (m-1)/(SecOne-1)];
end
for m=1:SecTwo
ColorSet(m+SecOne,:)=[0 (SecTwo-m)/(SecTwo) 1];
end
for m=1:SecThree
ColorSet(m+SecOne+SecTwo,:)=[(m)/(SecThree) 0 1];
end
for m=1:SecFour
ColorSet(m+SecOne+SecTwo+SecThree,:)=[1 0 (SecFour-m)/(SecFour)];
end
for m=1:SecFive
ColorSet(m+SecOne+SecTwo+SecThree+SecFour,:)=[(SecFive-m)/(SecFive) 0 0];
end
end