The Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Trapz calculations and patching the area between two graphs of numerical data
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Steven Albright

Posts: 1
Registered: 8/22/17
Trapz calculations and patching the area between two graphs of numerical data
Posted: Aug 22, 2017 6:04 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I'm new to Matlab so trying to piece together my learnings here. Thank you in advance.

What I'm trying to do is plot two different lines (baseline vs actual) taken at different sample times (not a curve or line). Basically the example is measuring the area between posted speed and measured actual speed. Those data entries are entries are added as variables and I then want to use trapz to calculate the value for each line separately, but just as important I want to shade in the area between the lines using patch.

One problem..

1. I can't figure out how to correctly shade in the area BETWEEN the plots using patching to represent trapazoid shaped figures. I did figure out how to do the math between the matrix of the data, and using patch show it but it's not in the right place, and doesn't handle decreasing values at all.

Please help!

Code so far:

figure
plot(mp,ts,'-*', mp, ats, '-*')
grid on
title('Speed')
xlabel('Mile Marker')
ylabel('Speed (mph)')
ylim([0 70]);
xlim([0 25]);
set(gca, 'XTick', 1:25)

xverts = [mp(1:end-1); mp(1:end-1); mp(2:end); mp(2:end)];
y1verts = [zeros(1,24); ats(1:end-1); ats(2:end); zeros(1,24)];
y2verts = [zeros(1,24); ts(1:end-1); ts(2:end); zeros(1,24)];
y3verts = y2verts-y1verts
p1 = patch(xverts,(y3verts),'g','LineWidth',1.5);



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.