How to remove specific rows

3 visualizaciones (últimos 30 días)
주희 박
주희 박 el 14 de Mzo. de 2022
Editada: KSSV el 14 de Mzo. de 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.

Respuesta aceptada

KSSV
KSSV el 14 de Mzo. de 2022
Editada: KSSV el 14 de Mzo. de 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

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by