function xbar(D,N,w);
% bar is placed x-axis;
% N is the number for the variable t;
% w is the width of bar.
% Example:
% M1: t1=2;t3=4;
% M2: t2=1;t5=7;t8=4;t6=4;
% M3: t4=3;t7=2;t9=4;
% M4: t10=3;t11=3;t12=2;
% Then D and N are equal to
% D=[2,4,0,0;
% 1,7,4,4;
% 3,2,4,0;
% 3,3,2,0];
% N=[1,3,0,0;
% 2,5,8,6;
% 4,7,9,0;
% 10,11,12,0];
% calling the file 'xbar.m' is
% xbar(D,N,0.2);
n=size(D,1);m=size(D,2);
if n>9;
error('The row number of D and N must be less 10');
end
for kn=1:n;
xs=0;
for km=1:m;
if N(kn,km)~=0;
plot([xs,xs+D(kn,km),xs+D(kn,km),xs,xs],...
[1+n-kn+w,1+n-kn+w,1+n-kn-w,1+n-kn-w,1+n-kn+w],'k');
hold on;
C=rand(1,3); %C is random color. It is also controlled by a certain data Nx3.
fill([xs,xs+D(kn,km),xs+D(kn,km),xs,xs],...
[1+n-kn+w,1+n-kn+w,1+n-kn-w,1+n-kn-w,1+n-kn+w],C);
text(xs+D(kn,km)/2,1+n-kn,['{itt}_{',num2str(N(kn,km)),'}'],...
'fontsize',14);
end
xs=xs+D(kn,km);
end
end
set(gca,'ytick',0:n);
S=[' 0'];
for k=1:n;
S(k+1,:)=['M',num2str(k)];
end
set(gca,'Yticklabel',S);
xlabel('makespan','fontsize',16);
图形如下:


