matlab - How to remove the entire row in a matrix after another matrix of the same dimension takes a value of 1 -
suppose have 2 matrices:
a= [0 0 0 0 1; 0 0 0 1 0; 1 0 1 0 1; 0 0 0 0 0; 0 0 1 1 1] b = [20 15 25 30 40; 12 15 25 38 24; 50 23 37 21 19; 7 20 89 31 41; 12 13 45 21 31]
how make entries in row of b nan first time 1 appears in a. in case want output be:
b = [20 15 25 30 nan; 12 15 25 nan nan; nan nan nan nan nan; 7 20 89 31 41; 12 13 nan nan nan]
thank in advance
you can use cummax
or cumsum
, logical indexing set values nan:
b(logical(cumsum(a,2)))=nan;
or
b(logical(cummax(a,2)))=nan;
Comments
Post a Comment