how to delete rows from matrix
古いコメントを表示
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
採用された回答
その他の回答 (3 件)
Jos (10584)
2016 年 5 月 26 日
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
2016 年 5 月 24 日
out=test_ary(~ismember(test_ary,[0 0 0],'rows'),:)
Anoire BEN JDIDIA
2016 年 10 月 14 日
0 投票
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 件のコメント
James Tursa
2016 年 10 月 14 日
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
2016 年 10 月 17 日
Hi, Thank you
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!