Area between two curves that plotted by importing datapoints

Hello
I have two curves imported from excel and ploted as shown in the figure below. How can I calculate the red area between the two curves. And also it is possible to assigned a color in the area.
clc
close all
clear all
a=xlsread('D:\Folder.xlsx','Sheet1','A1:A237');
b=xlsread('D:\Folder.xlsx','Sheet1','B1:B237');
x=linspace(80,250,237);
y = zeros(237,1);
y(:)=0.1465;
plot(x,y,a,b)

4 Comments

You have to figure out the crossing points. Once you have figured out the x that they have in common, then you can trapz() one, minus trapz() the other, to get the area between.
You would then also be able to use fill() . The trick there is to construct
XF = [first_x_ascending_order, fliplr(second_x_ascending_order)]
YF = [first_y_in_x_order, fliplr(second_y_in_x_order)];
fill(XF, YF)
That is, you want a line that goes along the first x, then backwards along the second x, so that you get back to the common origin.
I am practising with this, but get an error. The two curves intrsect at -0.3 and 3. Any help is appreciated!
clc
close all
clear all
x=linspace(-10,10,100);
y1=3*x;
y2=x.^2-1;
plot(x,y1,x,y2)
grid on
Area1=trapz(y1(-0.3,3.3));
Area2=trapz(y2(-0.3,3.3));
Area=Area1-Area2;

Sign in to comment.

Answers (0)

Tags

Asked:

on 20 Jun 2020

Commented:

on 21 Jun 2020

Community Treasure Hunt

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

Start Hunting!