selecting the closest possible date

1 visualización (últimos 30 días)
joseph Frank
joseph Frank el 30 de Abr. de 2011
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 comentarios
joseph Frank
joseph Frank el 30 de Abr. de 2011
I just want to find the rows that match my criteria
Oleg Komarov
Oleg Komarov el 30 de Abr. de 2011
Can you specify what you mean by "directly higher"?

Iniciar sesión para comentar.

Respuestas (1)

Teja Muppirala
Teja Muppirala el 30 de Abr. de 2011
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.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by