How to calculate the area of the green shaded region in MATLAB

2 ビュー (過去 30 日間)
Farhan
Farhan 2015 年 1 月 30 日
編集済み: Niels 2015 年 2 月 2 日
Hello,
Could you please guide me how to calculate the area of the green shaded region (between blue and red curve) of the attached figure in MATLAB. Please see the attached pic named "how to calculate area".
Blue line has the value of 1 p.u and is a straight horizontal line.
Thanks

回答 (3 件)

Image Analyst
Image Analyst 2015 年 1 月 30 日
Exactly what form is your data in? An image file? An equation? A list of (x,y) coordinates in a MATLAB variable? Do you have those 3 (x,y) pairs you show in the annotation? Exactly what are you starting with? If you have the three points, can't you just use the formula for a triangle: area = (1/2)*base*height???
  4 件のコメント
Farhan
Farhan 2015 年 1 月 30 日
Please find the new picture with zoomed in view.
Farhan
Farhan 2015 年 2 月 2 日
I have attached the zoomed in view in my previous message. File name "How to calculate area_zoomed"
I have tried using quad, for that it needs a function e.g. q = quad(fun,a,b)
i have a plot in the form of array in MATLAB workspace, but how to convert this array into a function?? So that it can be used to calculate area using quad?
Also please find the attached code and data file that is needed for code.

サインインしてコメントする。


Farhan
Farhan 2015 年 2 月 2 日
I have attached the zoomed in view in my previous message. File name "How to calculate area_zoomed"
I have tried using quad, for that it needs a function e.g. q = quad(fun,a,b)
i have a plot in the form of array in MATLAB workspace, but how to convert this array into a function?? So that it can be used to calculate area using quad?

Niels
Niels 2015 年 2 月 2 日
編集済み: Niels 2015 年 2 月 2 日
Is it not possible to simply calculate the difference between your y-values and the straight line, take the mean of every 2 neigboring y-values, then multiply those values by your x-spacing and then sum all the values between x = 2166 and x = 5590? ie.
spc = 1; % spacing of x-values
x = 1:spc:20; % full x-range
x_min = 5; % lower boundary of interest
x_max = 12; % upper boundary of interest
y = 30-0.5*x + rand(1,numel(x)); % y-values for full x-range
y_ref = 30; % reference value for y
y_means = mean([y(1:end-1); y(2:end)],1) - y_ref;
y_range = y_means(x(x==x_min):x(x==x_max-1));
y_int = sum(y_range*spc);
Or more simple:
y_int = trapz(x_min:x_max,y(x_min:x_max));

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by