Finding a row with multiple "closest values" (values with the least combined error)

9 次查看(过去 30 天)
Greetings Matlabians. I've ran into a bit of a puzzle. I have a 2D matrix that contains rows with columns ranging from 0.00 - 0.99. For example...
ranges = [0.011, 0.052, 0.076,... 0.987; 0.013, 0.018, 0.050, 0.071,... 0.999;...]
All rows contain slightly different values in this range, and some rows have a more narrow range. What I want to do is to extract the index of the row that contains the values that are, on average, closest to 0.05, 0.20, and 0.80. The optimum row will deviate from these three values the least. To measure deviation, I do not want to simply subtract the difference between the actual value and the desired value (0.51-0.50 = 0.01). Rather, it would be better to weight each difference by finding a percent difference (0.51-0.50 = 0.01/0.05). The row that has the smallest sum of all three percent differences wins. Also, note: the three values which are closest to my desired values (let's call them my approximate values) are found in different columns of each row. Finally, if it so happens that two values have the same magnitude of deviation from one of my desired values (i.e. there are two potential approximate values), I want to favor the smaller approximate value.
  6 个评论
qualiaMachine
qualiaMachine 2015-11-1
@Walter Roberson I hadn't thought about that. Good point. It is possible. If such a case were to arise, I would favor the smaller approximate value.
Image Analyst
Image Analyst 2015-11-1
So is only row 1 to be compared only to 0.05, and only row2 to be compared to only 0.20, and only row 3 to be compared to only 0.80 like this?
row1Diffs = abs(ranges(1,:) - 0.05);
row2Diffs = abs(ranges(2,:) - 0.20);
row3Diffs = abs(ranges(3,:) - 0.80);
Or is each row (all 3 rows) to be compared to each number (all 3 numbers), like this?
% Compare row 1 to all of the numbers.
row1Diffs(1) = abs(ranges(1,:) - 0.05);
row1Diffs(2) = abs(ranges(1,:) - 0.20);
row1Diffs(3) = abs(ranges(1,:) - 0.80);
% Compare row 2 to all of the numbers.
row2Diffs(1) = abs(ranges(2,:) - 0.05);
row2Diffs(2) = abs(ranges(2,:) - 0.20);
row2Diffs(3) = abs(ranges(2,:) - 0.80);
% Compare row 3 to all of the numbers.
row3Diffs(1) = abs(ranges(3,:) - 0.05);
row3Diffs(2) = abs(ranges(3,:) - 0.20);
row3Diffs(3) = abs(ranges(3,:) - 0.80);
What set of comparisons do you want to do?

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by