subsetting dates in a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Cagdas Ozgenc
el 1 de Nov. de 2013
Comentada: Cedric
el 1 de Nov. de 2013
Hello,
I have a time series in a matrix and first column is serial date numbers (up to millisecond precision), and other columns my samples. I would like to get those rows that belong to for example '12-Oct-2012'. I couldn't figure out how to write the logical operator to get a slice of this matrix. I would like to hopefully avoid some sort of slow string comparison.
Thanks in advance
Respuesta aceptada
Cedric
el 1 de Nov. de 2013
Editada: Cedric
el 1 de Nov. de 2013
You already have serialized/numeric time stamps in you array, so just convert date boundaries to numeric, and compare numbers: assuming your array is named data..
lb_incl = datenum( '12-Oct-2012', 'dd-mmm-yyyy' ) ;
ub_excl = datenum( '13-Oct-2012', 'dd-mmm-yyyy' ) ;
id = data(:,1) >= lb_incl & data(:,1) < ub_excl ;
dailyMean = mean( data(id,2) ) ;
or
dailySlice = data(id,2:end) ;
2 comentarios
Más respuestas (1)
Azzi Abdelmalek
el 1 de Nov. de 2013
If A is your cell array
c1=cellstr(datestr(A(:,1),'dd-mm-yyyy'))
idx=ismember(c1,'12-10-2012')
out=A(idx,:)
Ver también
Categorías
Más información sobre Time Series Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!