Azzera filtri
Azzera filtri

Removing Coordinates with a Negative Y Value

4 visualizzazioni (ultimi 30 giorni)
Elizabeth Kirkwood
Elizabeth Kirkwood il 5 Nov 2020
Modificato: Xiaobo Dong il 6 Nov 2020
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.

Risposte (1)

Xiaobo Dong
Xiaobo Dong il 5 Nov 2020
Modificato: Xiaobo Dong il 6 Nov 2020
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