MATLAB: How to plot the difference between y components for all x

difference between curvesplotting

I have plotted the energy consumption of two model house on one plot using roughly the following code (I do not have the exact code in-front of me):
t = 0:24; %hour of day
iEc = [measured values for model A]; %length =25
Ec = [measured values for model B;] %length = 25
figure
plot(t, iEc, '-or', t, Ec, '-ob'); %after this, there are graph labels
I am satisfied with how everything turned out but just as an extra feature, I'd like to add a line between the y component of the two curves at the same t value on the same graph. For example, at t = 1 , i'd like to plot a line from (y of iEc) to (y of Ec) and list the difference next to it. This is similar to what I'd like to do but I'd like to add the difference between the curves: i.stack.imgur.com/G2Azd.png
I'm not 100% on how to do this, but I was thinking a for loop may be the best way to do this for all t. Any help or suggestions are appreciated. Thank you.

Best Answer

Hi, I think this does what you are looking for:
plot(t, iEc, '-or', t, Ec, '-ob', [t; t], [iEc; Ec], '-k')
str = num2cell(abs(iEc-Ec));
Xoffset = t+.1; %X offset from vertical lines
Yoffset = min([iEc; Ec])+abs(iEc-Ec)/2; %midpoint of vertical lines
text(Xoffset, Yoffset, str)