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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -