MATLAB: Showing the distance between the two plots on two curves at regular intervals on the same plot

advanced plotting

for example two lines are plotted with equation line 1 x=t^2 and y=(0.5*(t^2))// path and line 2 y=2x+6 // which is boundary i want them within the boundary so discared other points
i want two display the distance between two lines at regular intervals on the same plot indicating the distance between them
t=0:0.2:10;
for k=1:length(t)
x(k)=t(k).^2;
y(k)=0.5*(t(k).^2)+10;
m(k)=(2*x(k))+6;
end
c=y<=m
l=y(c);
g=x(c);
plot(g,l)
hold
plot(x,m)
legend('path','boundary')
xlabel('x-axis')
ylabel('y-axis')

Best Answer

t=0:0.2:10;
% avoid loops wherenever possible, use element-wise operations instead
x=t.^2;
y=0.5*x+10; % the same as "y=0.5*t.^2+10;" but faster
m=2*x+6;
%
c=find(y<=m);
plot(x(c),y(c),'.-b',x(c),m(c),'*--r');
legend('path','boundary')
xlabel('x-axis')
ylabel('y-axis')