Logical indexing for matrix
Afficher commentaires plus anciens
Hi Everybody! I have difficulties with some logical indexing.
I have vector with time values. For example the date 1st january 2008 at 9:00:00 am would be
tvec=2008 1 1 9 0 0 and so on...
Tvec covers a whole year so it has 527040 rows and 6 columns.
How do I locate a specic period. For example 1st january 2008 from 9 to 10 am?
I tried this:
clear;clc;
period = [2008 1 1 9];
idx(:,1)=tvec(:,1)==period(1);
idx(:,2)=tvec(:,2)==period(2);
idx(:,3)=tvec(:,3)==period(3);
idx(:,4)=tvec(:,4)==period(4);
L=logical(idx);
tvec_a=tvec(L);
Thanks for any help you might have...
1 commentaire
per isakson
le 21 Nov 2014
Doesn't this work?
Réponse acceptée
Plus de réponses (1)
per isakson
le 21 Nov 2014
Modifié(e) : per isakson
le 21 Nov 2014
Replace
L=logical(idx);
by
L=logical( all(idx,2));
idx is already logical, no need apply the function, logical.
 
The datevec-format is not appropriate for this task when it comes to longer periods. Convert to serial date number.
sdn = datenum( tvec );
sdn1 = datenum( [2008,1,1, 9,0,0] );
sdn2 = datenum( [2008,1,1,10,0,0] );
Here is a problem with numerical precision. I prefer to carefully convert to seconds (whole numbers) to make comparisons simpler.
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!