what is the best way of finding which dates are consistent among differnet variables. For example:
a =
2010-04-23 12:45
2010-04-23 13:00
2010-04-23 13:15
2010-04-23 13:30
2010-04-23 13:45
2010-04-23 14:00
2010-04-23 14:15
b =
2010-04-23 12:45
2010-04-23 13:00
2010-04-23 13:15
2010-04-23 13:30
2010-04-23 13:45
2010-04-23 14:00
2010-04-23 14:15
should return
c =
1
1
1
1
1
1
1
where both a and b are character strings.
Engineero is correct assuming they are exactly the same format.
I read your question as you having dates of different formats, so 4-25-13 and 04.25.2013 would also return a 1 (for the same date)
In this case, store the datenum of each str in a vector datesA(i) = datenum(a{i})
, repeat for your B cell array, and then compare the vectors c=(A==B)
to get your result
If a
and b
are cell arrays of strings, then you can just use:
c = strcmp(a, b)
You would define a = {date_a1; date_a2; ...}
a = {date_a1; date_a2; ...}
a = {date_a1; date_a2; ...}
and b = {date_b1; date_b2; ...}
b = {date_b1; date_b2; ...}
b = {date_b1; date_b2; ...}
using that syntax to build a cell of strings. You reference an element in a cell almost the same way as you would an array. If you want the third result of c
, you would type c{3}
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.