I have two date vectors calculated using datevec. let's say u=[10 25; 10 26; 10 27; 10 28; 10 29; 10 30; 11 0; 11 1; 11 2]; v=[10 26; 10 27; 10 28; 10 29; 11 0; 11 0; 11 2];
So I want to match same dates in u and v and save the matched dates in a different vector. I used this syntax:
find_same_dates=ismember(u,v,'rows'); row_number=find(find_same_dates==1); matched_dates=u(row_number,:); matched_dates=[10 26; 10 27; 10 28; 10 29; 11 0; 11 2];
What should I do instead if I want matched_dates to have repeated values. for example, matched_dates=[10 26; 10 27; 10 28; 10 29; 11 0; 11 0; 11 2];
'ismember' syntax doesn't match the repeated rows

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 19 de Ag. de 2015
That depends on how you use ismember, you have also to specify if you are looking for dates in u or in v
u=[10 25; 10 26; 10 27; 10 28; 10 29; 10 30; 11 0; 11 1; 11 2];
v=[10 26; 10 27; 10 28; 10 29; 11 0; 11 0; 11 2]
find_same_dates=ismember(v,u,'rows');
matched_dates=v(find_same_dates,:)

3 comentarios

Pree
Pree el 19 de Ag. de 2015
Editada: Pree el 19 de Ag. de 2015
the length of u is larger than the length of v. So I want to match the dates of v with u. That is why I used this syntax: matched_dates= u(row_number,:);
row_number contains the row numbers of vector u that has same dates as in vector v.
But how should I tweak ismember syntax so it includes repeated rows? or what other functions can I use?
u=[10 25; 10 26; 10 27; 10 28; 10 29; 10 30; 11 0; 11 1; 11 2];
v=[10 26; 10 27; 10 28; 10 29; 11 0; 11 0; 11 2;45 45]
idu=ismember(u,v,'rows');
b=u(idu,:)
idv=ismember(v,b,'rows')
out=v(idv,:)
Pree
Pree el 19 de Ag. de 2015
Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 19 de Ag. de 2015

Comentada:

el 19 de Ag. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by