close all
x=(-3:0.0001:3)';
left=0;
right=2;
mu=0.5;
sigma=1;
x(find(x<left,1,'last'))=NaN;
x(find(x>left,1,'first'))=NaN;
x(find(x<right,1,'last'))=NaN;
x(find(x>right,1,'first'))=NaN;
y=tobitcdf(x,mu,sigma,left,right);
plot(x,y,'LineWidth',2)
hold('on')
stem(left,y(x==left),'Color','b')
stem(right,y(x==right),'Color','b')
title(['Tobit cdf when \mu=' num2str(mu) ', \sigma=' num2str(sigma) ', ' ...
'left=' num2str(left) ', right=' num2str(right)])
% x < left
xsmallerthanleft=left-rand;
text(xsmallerthanleft,tobitcdf(xsmallerthanleft,mu,sigma,left,right)+0.05, ...
'Pr(Tobit(\mu,\sigma^2,left,right)<left)=0 ','HorizontalAlignment','right')
% x =left
text(left,tobitcdf(left,mu,sigma,left,right)-0.01, ...
'Pr(Tobit(\mu,\sigma^2,left,right)<=left)=\Phi(left, \mu, sigma^2) ','HorizontalAlignment','right')
% left< x <right
xinside=unifrnd(left,right);
text(xinside,tobitcdf(xinside,mu,sigma,left,right)+0.01, ...
' Pr(Tobit(\mu,\sigma^2,left,right)<=x)=\Phi(x, \mu, \sigma^2) when x \in (left right)','HorizontalAlignment','left')
% x>=right
text(right,tobitcdf(right,mu,sigma,left,right)-0.01, ...
' Pr(Tobit(\mu,\sigma^2,left,right)<=right)=1','HorizontalAlignment','left')
ylim([0 1])