Removing Coordinates with a Negative Y Value
조회 수: 2 (최근 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.
댓글 수: 0
답변 (1개)
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);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!