How to calculate area below a line in an irregular plot?

I have an irregular channel with coordinates only known at vertices. I also know the depth of flow in this channel.
How can i find the area below the line (The flow area shaded in yellow)
x=[0,4,6,8,10,13,15,17] y=[0,-4,-4,-6,-6,-3,-4,0] The line is at -4.5

 Accepted Answer

KSSV
KSSV on 12 Jun 2017
Edited: KSSV on 12 Jun 2017
x=[0,4,6,8,10,13,15,17] ;
y=[0,-4,-4,-6,-6,-3,-4,0] ;
y1 = -4.5*ones(size(x)) ;
plot(x,y) ;
hold on
plot(x,y1,'r')
y1 = y(y<-4.5);
x1 = x(y<-4.5);
x1 = [6.5 x1 11.5] ; (6.5 and 11.5) are the x values at which y = -4.5 intersects calculated using ginput
y1 = [-4.5 y1 -4.5] ;
iwant = polyarea(x,y) ;

4 Comments

This is a specific case for -4.5, i actually need to find the area at multiple different values -4.5, -4, -3.5 etc.. Now if it was -3.5 there would be 4 intersections too. Additionally, is there a way to automatically tell the intersection coordinates at different depths?
x=[0,4,6,8,10,13,15,17] ;
y=[0,-4,-4,-6,-6,-3,-4,0] ;
y1 = -4.5*ones(size(x)) ;
plot(x,y) ;
hold on
plot(x,y1,'r')
P = InterX([x;y],[x;y1]) ;
y1 = y(y<-4.5);
x1 = x(y<-4.5);
x1 = [P(1,1) x1 P(1,2)] ;
y1 = [-4.5 y1 -4.5] ;
iwant = polyarea(x1,y1) ;
At present this covers only two intersection points...you need to check if intersections points are more then two...

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 12 Jun 2017

Commented:

on 6 Jul 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!