Removing Coordinates with a Negative Y Value

4 次查看(过去 30 天)
I'm attempting to find peak coordinate values but would like to restrict it to finding coordinates where the y value is positive. To approach this I am filtering the peak data after using the findpeak function.
%Find Peak Coordinates
[pks,locs]=findpeaks(y,x);
%Remove Coordinates were pks value are negative
pks=pks(pks>0);
locs=locs(pks>0);
This sucessfully removes the negative pks values but I need to retain its associated x value from the original data set. The code I used removes the number number of negative values deleted from the pks from the end of the locs rather than tying the corresponding values together. In this case, it deletes for the 4 negatives values from pks and then removes the last 4 (which is not the corresponding values) from locs.
How can I ensure that when a value in pks is removed its the corresponding locs value is also removed?
Thanks.

回答(1 个)

Xiaobo Dong
Xiaobo Dong 2020-11-5
编辑:Xiaobo Dong 2020-11-6
You can use a temporary variable to save the index. For example,
index = pks > 0;
pks = pks(index);
locs = locs(index);

Community Treasure Hunt

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

Start Hunting!

Translated by