# Compare each row of data with another vector data

2 vues (au cours des 30 derniers jours)
Ganesh Naik le 22 Nov 2022
Commenté : Ganesh Naik le 25 Nov 2022
Hi all, I have two vectors each of two columns, different row length.
A B
I would like to check each row of A with each/all of B (they have different row lengths) and would like to assign '1' for each row A if its value falls in any of row B's values. I could able to achieve the answer in case of one column. Any help in this regard highly appreciated. I have include the data here.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Matt J le 22 Nov 2022
tmp=[discretize(A,[B(:,1);inf],'Inc','left'),...
discretize(A,[-inf;B(:,2)],'Inc','right')];
out=all(tmp==tmp(:,1),2);
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Ganesh Naik le 22 Nov 2022
Hi Matt, thanks for this version of the answer as well.

Connectez-vous pour commenter.

### Plus de réponses (1)

Matt J le 22 Nov 2022
out=any(A(:,1)>=B(:,1).' & A(:,2)<=B(:,2).',2);
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Matt J le 22 Nov 2022
Modifié(e) : Matt J le 22 Nov 2022
Looks like you accepted the other one by mistake. However, I think the answer below is in fact the most efficient.
Ganesh Naik le 25 Nov 2022
Hi Matt thanks, I have accepted this answer now.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by