How to plot the difference between y components for all x?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Joel Miller
2017-12-12
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!