Function ISMEMBER indexes only the first value and leaves the rest

15 visualizzazioni (ultimi 30 giorni)
I'm having a problem with the () function, as it indexes the first value and leaves the duplicate values, the code below is in the figure and the table as well:
x = datetime(Date1,"Format","dd-MMM")
y = datetime(Date2,"Format","dd-MMM")
idx = ismember(x,y)
Input DataInput Data
What is the best solution to this problem?
  3 Commenti
Osama Shahin
Osama Shahin il 22 Apr 2022
@Star Strider The dates are repeated but the time I deleted (I changed the format from 'YYYY-MM-dd hh:mm' to 'YYYY-MM-dd'), originally the date y is a holidays and should extend the whole day, but it's recognized as only 1 hour!
Star Strider
Star Strider il 22 Apr 2022
That does not change the underlying data. Everything else is still there, since the 'Format' name-value pair only changes the display.
.

Accedi per commentare.

Risposte (1)

Bruno Luong
Bruno Luong il 22 Apr 2022
Modificato: Bruno Luong il 22 Apr 2022
ismember returns in the first argument the logical array, not the index. If you want the firs index (idx will be empty if there is no x in y)
idx = find(ismember(x,y),1,'first')
PS: your screen shot shows xx and yy not x and y.
  3 Commenti
Bruno Luong
Bruno Luong il 22 Apr 2022
A datetime is a time stamp; it does not have length ("whole day").
Date1 = ["01-Jan 11:22:33", "01-Jan 2:33:44" "02-Oct"];
Date2 = ["01-Jan 15:00:00", "02-Jan 2:33:44"];
x = string(datestr(datenum(Date1),"dd-mmm"))
x = 3×1 string array
"01-Jan" "01-Jan" "02-Oct"
y = string(datestr(datenum(Date2),"dd-mmm"))
y = 2×1 string array
"01-Jan" "02-Jan"
ismember(x,y)
ans = 3×1 logical array
1 1 0
Sean de Wolski
Sean de Wolski il 22 Apr 2022
I want to extend the date for the whole day (24hours) instead pf only the start hour of the day..
In that case, you should dateshift the timestamp to the start or end of the day so that you can then aggregate by day.

Accedi per commentare.

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by