How to remove specific rows

1 次查看(过去 30 天)
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
KSSV 2022-3-14
编辑:KSSV 2022-3-14
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by