Removing rows of a matrix based on rows of another matrix!
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Antonio
am 17 Jan. 2018
Beantwortet: Steven Lord
am 17 Jan. 2018
Imagine I have two matrices with different sizes (let's say 6x2 and 5x2) as follows:
A = [47 10;
29 10;
23 10;
34 10;
12 10;
64 10];
B = [23 20;
12 20;
54 20
47 20;
31 20];
I need to compare A(:,1) with B(:,1) and delete the rows in matrix A whose first-column-element is different from matrix B's first-column-element (so my focus is only on first columns of the matrices). So I should eventually get something like this:
A = [47 10;
12 10;
23 10];
as "47", "12", and "23" are the only first-column-elements in A that also exist in B! I have written this but I get the error "Matrix dimensions must agree."!
TF = A(:,1) ~= B(:,1);
A(TF,:) = [];
Any ideas how I could fix this?
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 17 Jan. 2018
Since it doesn't seem like ordering matters [you don't require A(n, 1) to match B(n, 1) as long as it matches some element in B(:, 1)] use the ismember function.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!