After you have found the minimum value of the function, you can simply replot over the same line in a different color. The most recently plotted object should cover any previously plotted objects by default.
If you were to save the value of the length on each iteration (for example, dtot(i+4)=dopt(i)), you could find the index of the minimum and replot that line just as you did in the for loop.
for i = -3:1:3
dtot(i+4)=dopt(i);
line(i)
hold on
end
[~,min_index] = min(dtot);
line(min_index,'Color','blue')
If you need the shortest possible line and not just the shortest line of the ones you plotted, you can perform the minimization and then plot the line using that value of
.