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

1 visualización (últimos 30 días)
Amy Xu
Amy Xu el 4 de Mayo de 2017
Respondida: James Tursa el 4 de Mayo de 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
];

Respuestas (1)

James Tursa
James Tursa el 4 de Mayo de 2017
C = B(ismember(B(:,1),A(:,1)),:);
D = C(C(:,2)==1,:);

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by