How to select values in an array until a known value

8 vues (au cours des 30 derniers jours)
Donato Stilla
Donato Stilla le 22 Juil 2020
Hello,
I will explain my problem. I have a 1x1701 sampled array "resampled_WF", once I found the max value of this array ("peak_WF"), I set a threshold 0.7*peak_WF, and I would like to select the farthest value in the array that gets nearer to this threshold.
Example:
As you can see, I was able to select ony the first value that resembles... but I would like to get the last one (around t=2 sec).
I tried to flip the array with "flip" function:
WF_threshold_input = 0.7*peak_WF;
flip_resampled_WF = flip(resampled_WF);
diff_peak_threshold = peak_WF - WF_threshold_input; %power loss at 70% power reduction
diff_peak_WF = peak_WF - flip_resampled_WF;
min_diff_threshold = min(abs(diff_peak_WF-diff_peak_threshold));
Doing that, MATLAB computes minimum difference on the whole array, I would like to stop at the first value, not considering further values.
I tried to select values with values<= WF_threshold_input, but again it selects over the whole dataset.
How can I select the value properly?
Thanks!!

Réponses (1)

Cris LaPierre
Cris LaPierre le 22 Juil 2020
I would probably use find.
  1. Identify the index of the peak value
  2. Identify the threshold value
  3. Using the index in #1, find the index of the first value that is <=threshold value starting at the peak. To get its index in the full WF data, you will need to add the index from #1 to the result. Something like this might work (untested)
ind = find(resampled_WF(indPk:end)<=WF_threshold_input,1) + indPk-1;

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by