Area under the Peak

3 ビュー (過去 30 日間)
iqra kiran
iqra kiran 2023 年 2 月 5 日
Hello,
I am using the following code to find the width, height and area of the peak,
load('data.csv')
X = data(:,1);
Y= data(:,2);
>> plot(X,Y)
findpeaks(Y,X,'MinPeakProminence',4,'Annotate','extents')
[pks,loc,w,p] =findpeaks(Y,X);
x = 1:length(data);
x_pks = x(loc);
area = trapz(x_pks, pks)
I am getting an error to find the area,as mentioned below
Array indices must be positive integers or logical values.
please suggest me the any solution.

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 5 日
Here is the corrected code;
clearvars; clc
load('data.csv')
X = data(:,1);
Y = data(:,2);
plot(X,Y)
findpeaks(Y,X,'MinPeakProminence',4,'Annotate','extents')
[pks,Loc,width,psrom] =findpeaks(Y,X);
findpeaks(Y,X)
x = X;
% if there are more than 1 peak, then it is necessary to specify which one
x1=Loc(1)-width(1)/2;
x2=Loc(1)+width(1)/2;
area = trapz([x1,x2], [pks(1), pks(1)])
  2 件のコメント
iqra kiran
iqra kiran 2023 年 2 月 6 日
Thank you.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 6 日
Most welcome

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by