I am trying to find the area as a part of a graph(Area-A and Area-B in the picture below). However, when I am using "trapz" function, it is not giving any output. Code is mentioned below and .mat file is attached. Please help me out.

조회 수: 1 (최근 30일)
clc;
a=importdata('anirban normal.mat');
b=a.data;
x=b(22810:25750,1);
figure();
plot(x);
Area=trapz(1:694);
x(x<0)=[];
findpeaks(x);
findpeaks(x,'MinPeakHeight',0.927);*

채택된 답변

KSSV
KSSV 2017년 3월 13일
편집: KSSV 2017년 3월 13일
a=importdata('anirban normal.mat');
b=a.data;
x=b(22810:25750,1);
figure();
plot(x);
% Area=trapz(1:694);
id = 1:length(x) ;
% Int = trapz(id,x) ;
% x(x<0)=[];
% findpeaks(x);
% findpeaks(x,'MinPeakHeight',0.927);
[val,maxid] = max(x) ;
Area1 = trapz(id(1:maxid),x(1:maxid)) ;
Area2 = trapz(id(maxid:end),x(maxid:end)) ;
Area = trapz(id,x) ;
Check Area = Area1+Area2
  댓글 수: 3
Biswarup  Dutta
Biswarup Dutta 2017년 3월 15일
Hello KSSV, area is derived. Thanks for your help. Is there any way to select Area 1 and Area 2, paint it with different colors using matlab code. I have tried something like that but it does not work:
clc
a=importdata('robin roy.mat');
b=a.data;
x=b(22000:25830,1);
plot(x);
x(x<0)=[];
findpeaks(x);
findpeaks(x,'MinPeakHeight',1.15);
Area1 = trapz(id(1:447),x(1:447)) ;
Area2 = trapz(id(447:1815),x(447:1815)) ;
hold on
ha1 = area(x(x<=447), y(x<=447), 'FaceColor','g');
ha2 = area([447 x0], [y(x == 447) 0], 'FaceColor','r');
hold off
A1str = sprintf('Area 1 = %6.3f', Area1);
A2str = sprintf('Area 2 = %6.3f', Area2);
legend([ha1 ha2], A1str, A2str)
I have uploaded the .mat file. The graph is similar to above one, I have attached.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by