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

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

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!

Sign in to comment.

Answers (1)

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

Hi Star Strider and Image Analyst, thanks for your reply! :)
I try to specify my question:
I collect the data of an acoustic measurement, lasting 300ms. Picture 1 of my first post shows the whole signal, picture two is more or less a "zoom in" to the region of interest.
timeMsT -> variable containing x-values
chA -> variable containing y- values, both 300000x1
% Finding Max Peak:
[pks1,locs1] = findpeaks(chA,timeMsT,'MinPeakHeight',10);
Amplitude1 = max(pks1);
% Finding its "x-value" / time:
time1 = find(chA == Amplitude1, 1, 'last');
Amplitude1Time = timeMsT(time1);
% Finding Min Peak:
chAinverted = -chA;
[pks2,locs2] = findpeaks(chAinverted,timeMsT,'MinPeakHeight',20);
Amplitude2 = max(pks2);
% Finding its "x-value" / time:
time2 = find(chA == -Amplitude2, 1, 'first');
Amplitude2Time = timeMsT(time2);
% Interesting range:
xl = find(chA == Amplitude1Time-0.05, 1, 'first');
xr = find(chA == Amplitude2Time+0.05, 1, 'first');
Now i want to create two new variables, for example chAnew and timenew, containing only the data of the region of interest, between xl and xr. Then i want to identify the peaks in the new set of data.
May i use:
chAnew = chA(xl:xr);
timenew = timeMsT(xl:xr);
Kind regards Georg
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!

Sign in to comment.

Asked:

on 23 Jul 2016

Commented:

on 23 Jul 2016

Community Treasure Hunt

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

Start Hunting!