pick one value per munite

1 visualización (últimos 30 días)
Rica
Rica el 20 de Mayo de 2016
Editada: Azzi Abdelmalek el 20 de Mayo de 2016
Hi all,
i have such an date time Array:
'18-May-2016 14:04:17'
'18-May-2016 14:05:07'
'18-May-2016 14:05:54'
'18-May-2016 14:06:43'
'18-May-2016 14:07:34'
'18-May-2016 14:08:25'
'18-May-2016 14:09:15'
'18-May-2016 14:10:07'
'18-May-2016 14:10:57'
'18-May-2016 14:11:48'
'18-May-2016 14:12:39'
'18-May-2016 14:13:30'
'18-May-2016 14:14:22'
'18-May-2016 14:15:12'
'18-May-2016 14:16:03'
'18-May-2016 14:16:54'
how could i clear the repeated munite values? for exemple : 18-May-2016 14:05:54 , '18-May-2016 14:10:07' and '18-May-2016 14:16:54'.
Thank you all

Respuesta aceptada

Guillaume
Guillaume el 20 de Mayo de 2016
Editada: Guillaume el 20 de Mayo de 2016
To start with, I would convert the datestr array to datetime and just work with that for the rest of your code.
To perform the filtering, you use unique as per Azzi's answer:
A={'18-May-2016 14:04:17'
'18-May-2016 14:05:07'
'18-May-2016 14:05:54'
'18-May-2016 14:06:43'
'18-May-2016 14:07:34'
'18-May-2016 14:08:25'
'18-May-2016 14:09:15'
'18-May-2016 14:10:07'
'18-May-2016 14:10:57'
'18-May-2016 14:11:48'
'18-May-2016 14:12:39'
'18-May-2016 14:13:30'
'18-May-2016 14:14:22'
'18-May-2016 14:15:12'
'18-May-2016 14:16:03'
'18-May-2016 14:16:54'}
A = datetime(A); %convert to datetime. In your cases, datetime is clever enough that you don't even need to specify the format
[~, indextokeep] = unique(A.Minute); %see how easy it is to extract the minutes
filteredA = A(indextokeep)

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 20 de Mayo de 2016
Editada: Azzi Abdelmalek el 20 de Mayo de 2016
A={'18-May-2016 14:04:17'
'18-May-2016 14:05:07'
'18-May-2016 14:05:54'
'18-May-2016 14:06:43'
'18-May-2016 14:07:34'
'18-May-2016 14:08:25'
'18-May-2016 14:09:15'
'18-May-2016 14:10:07'
'18-May-2016 14:10:57'
'18-May-2016 14:11:48'
'18-May-2016 14:12:39'
'18-May-2016 14:13:30'
'18-May-2016 14:14:22'
'18-May-2016 14:15:12'
'18-May-2016 14:16:03'
'18-May-2016 14:16:54'}
a=datevec(A,'dd-mm-yyyy HH:MM:SS')
min1=a(:,end-1)
[~,ii]=unique(min1,'stable');
out=A(ii,:)
  2 comentarios
Rica
Rica el 20 de Mayo de 2016
Hi, thank you for the answer. My array is long. it goes from 15-May to 18-May. the unique function is not approprieate in this cas, i think?
Guillaume
Guillaume el 20 de Mayo de 2016
Editada: Guillaume el 20 de Mayo de 2016
@Azzi, please don't use min as a variable name (overrides the min function). You're teaching bad habits in your examples!
@Rica, well you're asking to remove duplicates and hence to obtain unique minutes. The unique function is the most appropriate for this. The length of your array is irrelevant, whichever scheme you could come up with will be slower than unique.
Also, I would recommend using datetime instead of datevec. As a matter of fact, I would simply convert the datestring array into datetime and just use that for future processing. datetime is a lot easier to use

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time 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