Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Amy Xu
Amy Xu am 4 Mai 2017
Beantwortet: James Tursa am 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
];

Antworten (1)

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

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by