selecting the closest possible date

1 次查看(过去 30 天)
joseph Frank
joseph Frank 2011-4-30
Hi ,
I have the following matrix:
1226 727198
1226 727563
1226 727929
1226 728294
1226 728659
1226 729024
1226 729390
1238 727198
1238 727563
1238 727929
1238 728294
1238 728659
1238 729024
1238 729390
1238 729755
1238 730120
1238 730485
1238 730851
1238 731216
1255 727198
1255 727563
1255 727929
1255 728294
1255 728659
1255 729024
where the first column is an ID and the second is date. I have a date X=728628.Is there a simple line or function that would enable me to select from each unique ID the date which is directly higher than X .i.e i want for each unique ID the date which is higher but closest to 728628. I can do that by writing many lines but i have the feeling that there is a very simple and direct way to do so.
  3 个评论
joseph Frank
joseph Frank 2011-4-30
I just want to find the rows that match my criteria
Oleg Komarov
Oleg Komarov 2011-4-30
Can you specify what you mean by "directly higher"?

请先登录,再进行评论。

回答(1 个)

Teja Muppirala
Teja Muppirala 2011-4-30
If your matrix is M, and you have the Statistics Toolbox, then:
X = 728628;
grpstats(M(:,2),M(:,1),@(z)min(z(z > X)))
This returns
ans =
728659
728659
728659
Which is the first number higher than 728628 for each of the 3 groups.

类别

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