# How to remove specific rows

1 view (last 30 days)
주희 박 on 14 Mar 2022
Edited: KSSV on 14 Mar 2022
Hello
I have two datas and they are corresponded. I want to delete rows which is zero value in a. And I also want to delete same rows in b(a and b are different datas so b doesn't have zero)
a=1000X1; %a = [3 5 2 0 8 6 3 3 5 1 0 5 0 3 2 1 6 0 4 3 0 .........nonregular
b=1000X1;
So first i found rows that have zero using below code
zerorows=find(a(:,1)==0);
And I know I can delete zero rows in a using below code.
a1=nonzeros(a);
Finally I want to delete a1 in b.
I've trying several methods like
b(a1,1)=[];
But nothing works.Thank you. And I can't use 'removerows' now. So I need other methods.

KSSV on 14 Mar 2022
Edited: KSSV on 14 Mar 2022
idx = a == 0 ; % find indices of zeroes in a
b(idx) = [] ; % remove the respective values from b
If a is floating point numbers (which are mostly), you should prefer using this:
tol = 10^-5 ;
idx = abs(a)<=tol ; % find indices of zeroes in a
b(idx) = [] ; % remove the respective values from b