Effacer les filtres
Effacer les filtres

How to quary (building a new matrix based on some information)

1 vue (au cours des 30 derniers jours)
Amy Xu
Amy Xu le 4 Mai 2017
Matrix A & B are as follow. I want to create matrix C, where it includes only ID(s) available from A in B.
A = [
145654
145834
];
B = [
145654 1 1 5 1
145654 1 1 5 1
145654 1 1 5 1
145654 2 1 5 1
145654 2 1 5 1
145654 3 1 5 1
145654 3 1 5 1
145654 4 1 5 1
145654 9 1 5 1
145654 10 1 5 1
145654 10 1 5 1
145655 1 1 5 1
145655 1 1 5 1
145655 1 1 5 1
145655 1 1 5 1
145655 2 1 5 1
145655 3 1 5 1
145655 3 1 5 1
145655 4 1 5 1
145655 4 1 5 1
145655 4 1 5 1
145655 5 1 5 1
145655 7 1 5 1
145655 8 1 5 1
145655 9 1 5 1
145655 9 1 5 1
145655 10 1 5 1
145655 10 1 5 1
145655 10 1 5 1
145655 10 1 5 1
145655 10 1 5 1
145655 10 1 5 1
145834 1 1 1 6
145834 1 1 1 6
145834 2 1 1 6
145834 2 1 1 6
145834 3 1 1 6
145834 3 1 1 6
145834 4 1 1 6
145834 9 1 1 6
145834 10 1 1 6
145834 10 1 1 6
145834 10 1 1 6
145834 10 1 1 6
];
C = [
145654 1 1 5 1
145654 1 1 5 1
145654 1 1 5 1
145654 2 1 5 1
145654 2 1 5 1
145654 3 1 5 1
145654 3 1 5 1
145654 4 1 5 1
145654 9 1 5 1
145654 10 1 5 1
145654 10 1 5 1
145834 1 1 1 6
145834 1 1 1 6
145834 2 1 1 6
145834 2 1 1 6
145834 3 1 1 6
145834 3 1 1 6
145834 4 1 1 6
145834 9 1 1 6
145834 10 1 1 6
145834 10 1 1 6
145834 10 1 1 6
145834 10 1 1 6
];
And finally, I want to create matrix D, where arrays in first column of matrix C are equal only to 1:
D = [
145654 1 1 5 1
145654 1 1 5 1
145654 1 1 5 1
145834 1 1 1 6
];

Réponses (1)

James Tursa
James Tursa le 4 Mai 2017
C = B(ismember(B(:,1),A(:,1)),:);
D = C(C(:,2)==1,:);

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by