How to check and update one matrix by comparing the element of another matrix?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
suchismita
am 17 Apr. 2015
Kommentiert: suchismita
am 17 Apr. 2015
I have a matrix 10*3
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
now i want to check whether second and third column pairs are existing in another 10 by 2 matrix or not
example:
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
and if any pair from 10 by 3 matrix is not able to satisfy the condition will be removed.
for example:
in first row 1 2 3 -- 2 3 is available in 10*2 matrix so will keep that row as it is but if this condition is not satisfied, the entire row will be removed from 10*3 matrix
please please help me.
0 Kommentare
Akzeptierte Antwort
Guillaume
am 17 Apr. 2015
Bearbeitet: Guillaume
am 17 Apr. 2015
A = [1 2 3; 1 2 4; 1 2 5; 1 3 4; 1 3 5; 1 4 5; 2 3 4; 2 3 5; 2 4 5; 3 4 5];
B = [1 2; 2 3; 4 5]; %reduced second matrix so some rows of A are missing
isrowpresent = ismember(A(:, [2 3]), B, 'rows');
A(~isrowpresent, :) = [] %delete rows not present
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices 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!