Removing Coordinates with a Negative Y Value
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Xiaobo Dong
on 5 Nov 2020
Edited: Xiaobo Dong
on 6 Nov 2020
You can use a temporary variable to save the index. For example,
index = pks > 0;
pks = pks(index);
locs = locs(index);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!