How to identify min and max within a specific range of a matrix?
14 views (last 30 days)
Show older comments
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 Comment
Star Strider
on 23 Jul 2016
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!
Answers (1)
Image Analyst
on 23 Jul 2016
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 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!