How do you find the value that is closest to a desired value but also meets other criteria?

1 view (last 30 days)
I am working with a set of data that crosses the y-axis multiple times (see attached Excel sheet) and I would like to find the average load value that has the closest corresponding x-axis value to the number 2. As you can see from the plot, the data crosses over the line x = 2 numerous times, so there is a good chance that I will get the load value from one of the "higher" crossovers if I only look for the value closest to 2. In summary, I would like to identify the point that has a compliance offset (x value) that is closest to 2 but also comes from the lower portion of the curve. Unfortunately, I cannot set a hard upper limit so that the script searches below a certain value because this script will be used for many different materials systems and that value will not always be known. I was attempting to find this value with the following code:
targetedComplianceOffset = 2;
tmp = abs(complianceOffsetArray-targetedComplianceOffset);
minValue = min(tmp);
indexComplianceOffset2 = find(tmp == minValue);
minimumComplianceOffset(i) = complianceOffsetArray(indexComplianceOffset2);
minCorrectedLoad2(i) = averageLoadArray(indexComplianceOffset2);
As mentioned above, please find attached a sample plot with a representative amount of data.

Answers (1)

Image Analyst
Image Analyst on 26 Jun 2014
Edited: Image Analyst on 26 Jun 2014
Do you have the Signal Processing Toolbox? If so you could probably calculate -abs(2-x) and then send that in to findpeaks() to get all the points that are closest to 2.
  1 Comment
Zachary
Zachary on 26 Jun 2014
No, I do not have the Signal Processing Toolbox. I had identified this as a potential solution but the eventual end user will not have this toolbox so I have to go without.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!