How to search row and delete row?

3 visualizzazioni (ultimi 30 giorni)
Triveni
Triveni il 27 Feb 2016
Risposto: Guillaume il 27 Feb 2016
x= [15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 0];%Initial guess
a = unique(x); % unique elements
y = repmat(x,numel(a),1);%repeat x matrix
y(:,end) = a'; %replace last column by transpose(a)
%output
y= [15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 -45;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 -30;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 0;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 15;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 30;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 45;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 60;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 90;];
I want to delete row which matching with "x" and store it into "value".
value = [15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 -45;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 -30;
%row of initial guess "x" should be deleted.
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 15;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 30;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 45;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 60;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 90;];

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 27 Feb 2016
Modificato: Andrei Bobrov il 27 Feb 2016
x= [15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 0];
a = unique(x);
b = a(a ~= x(end));
value = ones(numel(b),1)*x;
value(:,end) = b;

Più risposte (1)

Guillaume
Guillaume il 27 Feb 2016
Either of these would work:
value = y(~all(bsxfun(@eq, y, x), 2), :)
Or
value = y(~ismember(y, x, 'rows'), :)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by