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

조회 수: 9 (최근 30일)
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

채택된 답변

Jonas
Jonas 2021년 6월 8일
편집: Jonas 2021년 6월 9일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by