Lookup Table the floor value

조회 수: 5 (최근 30일)
Jorge
Jorge 2011년 4월 12일
I´m a new user of Matlab and I´m trying to get the y floor value of a table. I´ve looking for it and the interpn1 command only let you to get the nearest value not the floor.
An example is for the table:
1 10
10 30
If I ask for the value of 9, I need to get 10 (if I use interpn1 nearest I get 30).
Thanks in advance

채택된 답변

Mike Hosea
Mike Hosea 2011년 4월 12일
For a table x,y with x sorted ascending, you can do a linear time lookup for the value xi in the "floor" sense via
y(find(xi>=x,1,'last'))
-- Mike

추가 답변 (4개)

the cyclist
the cyclist 2011년 4월 12일
If A is your array, I think you want something like:
y_floor = min(A(A>9))

Andrei Bobrov
Andrei Bobrov 2011년 4월 12일
added variant
A = randi(120,5,5)
n = 9
[~,I] = min(abs(A(:)-n));
A(I)

Walter Roberson
Walter Roberson 2011년 4월 12일
Use the two output form of histc() to get the bin numbers, and use the bin numbers to index the y table.

Jorge
Jorge 2011년 4월 13일
Thank you every one.
I´m using the find command to do it and it seem to works perfect.
find (A(:,1)<=9,1,'last')

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by