Finding the Closest Value to an Input Value from a Table Column

37 次查看(过去 30 天)
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));

采纳的回答

Cris LaPierre
Cris LaPierre 2020-7-20
编辑:Cris LaPierre 2020-7-20
Find the minimum of the absolute value of the difference.
[val,idx] = min(abs(x-y))
You can read more about what the outputs are here.
  2 个评论
Jake Bowd
Jake Bowd 2020-7-20
Thanks, Cris.
I have now spent some time reading the documentation on Min. It would appear it is the right approach to take, although not using the 'abs' function.
However, I cannot find a way to put a condition into the equation such that the following finds the minimum value after a specified row number, for example row 40.
[val,idx] = min(x);
Cris LaPierre
Cris LaPierre 2020-7-20
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));

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 ECG / EKG 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by