finding closest value in specific row and columm and take value intersecting these.

Hello,
I a have this matrix M for simplification
[120 1.2 1.3 1.4
100 2.2 2.3 2.4
50 3.2 3.3 3.4
0 4.2 4.3 4.4
NaN 0 1000 2200]
and i need to find closest value from first row (1) and last column (5) and take value from intersection of these.
for example a have a variables a=60 (need closest from 1st row) and b=1200 (need closest from 5th column) and i need to return x=3.3
Thanking in advance for your time

 Accepted Answer

first thing: you confused rows and columns, you have 5 rows and 4 columns, not the other way around (at least it appears like that on my page and your ; are missing to indicate new rows)
so you want to find intersection of closest element of first column and last row
the intersection is
[~,rowIdx]=min(abs(matrix(:,1)-a));
[~,colIdx]=min(abs(matrix(end,:)-b));
intersectionValue=matrix(rowIdx,colIdx)

More Answers (0)

Categories

Products

Asked:

on 8 Jun 2021

Edited:

on 9 Jun 2021

Community Treasure Hunt

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

Start Hunting!