How to identify min and max within a specific range of a matrix?

14 次查看(过去 30 天)
Hi everyone!
I have a set of data (200000x1 matrix), shown in the first attachment:
Now I want to focus on specific range around the first (highest) peak. I was able to plot only the interesting region and to mark the peaks by using:
plot(timeMsT,chA,'b');
...
plot(locs1,pks1,'rs','MarkerFaceColor','r');
hold on;
plot(locs2,-pks2,'rs','MarkerFaceColor','r');
...
See second attachment:
Now i want to identify (=getting x- and y-value) the three peaks that are marked, as well as a fourth one (the first positive peak). I was able to identify the highest positive and the lowest negative one, using:
MAXIMUM:
[pks1,locs1] = findpeaks(chA,timeMsT,'MinPeakHeight',10);
Amplitude1 = max(pks1);
MINIMUM:
chAinverted = -chA;
[pks2,locs2] = findpeaks(chAinverted,timeMsT,'MinPeakHeight',20);
Amplitude2 = max(pks2);
I don't know how to identify x- and y-value of the other peak(s). Is it possible to create a new matrix element out of "chA" (200000x1), which contains only the specific range of data?
I tried:
chAnew = chA(left:right)
as well as
chAnew = chA([left right])
, but it didn't work.
Kind regards
Georg
  1 个评论
Star Strider
Star Strider 2016-7-23
Georg Gamauf Commented (14.00 UTC)
Guys! I just found the solution. I simply had to set the range to
xl = time1-50;
xr = time2+50;
chAnew = chA(xl:xr);
timenew = timeMsT(xl:xr);
because time1 and time2 were already set as indices of the highest and the lowest peak!

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2016-7-23
chA(left:right) should work to crop out a section, while the second line of code you tried won't. Perhaps you didn't calculate left and right properly. You'd also need to crop out the timeMsT values too, unless you just wanted to work with indexes from the new, shorter array.
  3 个评论
Georg Gamauf
Georg Gamauf 2016-7-23
Guys! I just found the solution. I simply had to set the range to
xl = time1-50;
xr = time2+50;
chAnew = chA(xl:xr);
timenew = timeMsT(xl:xr);
because time1 and time2 were already set as indices of the highest and the lowest peak!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by