Filter löschen
Filter löschen

How to remove particular rows from a matrix?

3 Ansichten (letzte 30 Tage)
Cantor Set
Cantor Set am 22 Feb. 2020
Bearbeitet: Walter Roberson am 22 Feb. 2020
I need to remove particular row from a matrix A but only once, example:
A=[1 2 3 4; 1 2 3 4; 1 2 3 4; 1 1 1 1; 7 8 9 0]; y=[1 2 3 4; 1 1 1 1]; %the rows [1 2 3 4] in y occurs 3 times in A, I want to remove it only once
so setdiff(A,y, 'rows'); wont work.
But I need something general that works for arbitrary A and y
Thank you :)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 22 Feb. 2020
Bearbeitet: Walter Roberson am 22 Feb. 2020
[found, idx] = ismember(y, A, 'rows');
A(idx(found). :) = []; %delete one copy of the found ones

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and 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