Filter löschen
Filter löschen

How to find position of a time vector in another time vector?

1 Ansicht (letzte 30 Tage)
roudan
roudan am 12 Dez. 2017
Kommentiert: Jan am 12 Dez. 2017
Hi
I have two time vectors, one has random time spacing like A=[' 01/01/2001', '05/01/2001, ....], the other time vector has daily time like B=[' 01/01/2001', '01/02/2001', ....]. I like to find a position of each element of A in vector B. What is the fastest way? I don't want to write a loop for find each element. is there a faster way to output a position vector directly? Thanks a lot. I appreciate your help.
  1 Kommentar
Jan
Jan am 12 Dez. 2017
Bearbeitet: Jan am 12 Dez. 2017
What exactly is a "time vector"?
A=[' 01/01/2001', '05/01/2001]
is the same as:
A = ' 01/01/200105/01/2001'
So it is not clear, what your inputs are. Does the leading space have a meaning? Is it a cell string or a datetime object?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 12 Dez. 2017
While I'm not sure what your inputs are, most likely this will solve the problem:
[ex, loc] = ismember(A, B)
  2 Kommentare
roudan
roudan am 12 Dez. 2017
Thanks Jan. That works perfectly. I also found solution like this which has same result. idxs =arrayfun(@(x)find(B==x,1),A)
Jan
Jan am 12 Dez. 2017
I assume the arrayfun method is much slower.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by