Delete rows with 0 for specific columns in Matlab

前端 未结 2 1873
暖寄归人
暖寄归人 2021-01-28 15:52

So I want to delete rows of a matrix that contain zero, but only for specific columns. For example:

A = [[0 0 0 0; 1 2 0 4; 2 0 1 1; 0 0 0 0; 1 2 3 4; 0 1 2 3];
         


        
2条回答
  •  不要未来只要你来
    2021-01-28 16:32

    This is easily solved using the find() function:

    B = A(find(A(:,2)~=0),:)
    

    find() by default returns rows, so calling it in this case returns the index of the rows where the value on the second column is not 0.

提交回复
热议问题