function pltdvh(x, T, Spl, Spr, As, Ab)

if nargin ~= 6
  error('Six input arguments are required.')
end
dmax = 80;
Y = [];
% for target
x = x(:);
d = T*x;
y = dvh(d, dmax);
Y = [Y y];
L{1} = 'CTV';

% for Parotoid Left
d = Spl*x;
y = dvh(d, dmax);
Y = [Y y];
L{2} = 'Parotoid L';

% for Parotoid Right
d = Spr*x;
y = dvh(d, dmax);
Y = [Y y];
L{3} = 'Parotoid R';


% for Spinal cord
d = As*x;
y = dvh(d, dmax);
Y = [Y y];
L{4} = 'Spinal cord';


% for Brainstem
d = Ab*x;
y = dvh(d, dmax);
Y = [Y y];
L{5} = 'Brainstem';

figure;
t = 0:dmax;
plot(t,Y)
legend(L)
grid on
xlabel('Dose (Gy)')
ylabel('Fractional vol.')

%+++++++++++++++++++++++++++
function y = dvh(d,dmax)

m = length(d);
t = 0:dmax; t = t'; n = length(t);
y = zeros(n,1);
for i=n:-1:1
  I = find(d >= t(i));
  y(i) = y(i) + length(I);
  y(1:i-1)=y(1:i-1) + length(I);
  ind = setdiff(1:length(d),I);
  d = d(ind);
end
y = y/m;
