|
"dhruv sharma" <stnfrd1980@yahoo.com> wrote in message <i265ej$aqv$1@fred.mathworks.com>...
> I want to find the first occurrence of 1 in each row of a binary matrix and convert all other elements to 0 AND convert all elements to the right of 1 to one. For example.
> A = [0 0 0 1; 1 0 0 1; 0 0 0 0; 0 1 0 0]. Then I want two matrices: A1 = [ 0 0 0 1; 1 0 0 0; 0 0 0 0; 0 1 0 0] and A2 = [0 0 0 1; 1 1 1 1; 0 0 0 0; 0 1 1 1]. Thank you very much.
- - - - - - - -
A2 = +(cumsum(A,2)>0);
A1 = diff([zeros(size(A,1),1),A2],1,2);
Roger Stafford
|