1

I have a Matrix A of 1000 rows and 2 columns.

A = [0.0325 5.6 ; 0.0367 7.6 ; 0.0391 8.1 ; 0.0404 9.7; etc.]

I want to find the matching element in the 2nd column for a given value that is not necessarily in the first column.

For instance, for a given value 0.0371, I would want a value of 7.6 since it corresponds to the 2nd column value of the element that is the closest from my input 0.0371 (0.0367).

For 0.0393, I want 8.1, etc.

4

1 回答 1

1

您可以计算每个元素与所需值之间的差异,然后找到最小值的索引。您想要的值将位于第 2 列中的索引处。

[~,idx] = min(abs(A(:,1)-testval));
desiredval = A(idx,2);
于 2013-10-26T22:16:04.333 回答