Filter löschen
Filter löschen

how to delete rows from matrix

1 Ansicht (letzte 30 Tage)
m. muner
m. muner am 24 Mai 2016
hello i have 53*3 matrix but include rows that three column of the row are zeros i want to delete the entire row i tried this but since every delete shift the location of the other rows i had problem with the for loop so what can i do to overcome this
[c u]=size(test_ary); %dimensions
for i=1:c
for b=1:u
if(test_ary(i,1)==(o)));
test_ary(i,:)=[];
end
end
end

Akzeptierte Antwort

James Tursa
James Tursa am 24 Mai 2016
Bearbeitet: James Tursa am 24 Mai 2016
Replace your for-loop with this vectorized code:
x = all(test_ary==0,2); % Which rows are all 0's
test_ary(x,:) = []; % Delete those rows
  1 Kommentar
m. muner
m. muner am 26 Mai 2016
not working its give the same matrix

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

Jos (10584)
Jos (10584) am 26 Mai 2016
Using the statement "test_ary(i,:) = []" you will change the size of it, which will cause problems!
tf = all(test_ary==0,2) % true for rows with only 0's
test_ary(tf,:) = [] % remove those rows using logical indexing

Azzi Abdelmalek
Azzi Abdelmalek am 24 Mai 2016
out=test_ary(~ismember(test_ary,[0 0 0],'rows'),:)
  2 Kommentare
m. muner
m. muner am 26 Mai 2016
just create new matrix called out which is same as the original test_ary
Azzi Abdelmalek
Azzi Abdelmalek am 26 Mai 2016
No, this is not true

Melden Sie sich an, um zu kommentieren.


Anoire BEN JDIDIA
Anoire BEN JDIDIA am 14 Okt. 2016
I have a big matrix 599794x2 i want to delete rows which contains values which repeats for exemple if A=[1,1;2,1;3,1;4,1;5,2;6,2;7,2]; i want to have A=[1,1;5,2]
  2 Kommentare
James Tursa
James Tursa am 14 Okt. 2016
In the future open up a new Question for this rather than piggyback on an existing Question. But I will answer this here this time:
A = A(logical([1;diff(A(:,2))]),:);
Anoire BEN JDIDIA
Anoire BEN JDIDIA am 17 Okt. 2016
Hi, Thank you

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing 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