Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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
];

Risposte (1)

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

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by