Finding the Closest Value to an Input Value from a Table Column
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jake Bowd
le 20 Juil 2020
Commenté : Cris LaPierre
le 20 Juil 2020
I have the below code that finds a value that is less than or equal to RESULTS.Vertical_Heel_Trajectory_at_HS1(1,1) in the following table column RESULTS.Inverse_Kinematics_Tables{1,1}.(ab{1,1} and names it RESULTS.Second_HS_Thresholding.
The issue I have is that values are sometimes not always less than or equal to, but is very close. I would therefore like to change the code so that it picks up the closest value to RESULTS.Vertical_Heel_Trajectory_at_HS1(1,1) value.
I have also attached a figure to illustrate this point further.
RESULTS.Second_HS_Thresholding= find(any(RESULTS.Inverse_Kinematics_Tables{1,1}.(ab{1,1})<= RESULTS.Vertical_Heel_Trajectory_at_HS1(1,1),2));
0 commentaires
Réponse acceptée
Cris LaPierre
le 20 Juil 2020
Modifié(e) : Cris LaPierre
le 20 Juil 2020
Find the minimum of the absolute value of the difference.
[val,idx] = min(abs(x-y))
2 commentaires
Cris LaPierre
le 20 Juil 2020
You will need to use abs if you want the closest value - above or below the threshold. If you only want to find a subset of data (a new requirement not mentioned in your OP), you need to pass in the subset of data to min.
[val,idx] = min(x(40:end));
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Transforms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!