MATLAB: How i can put the (-1) in binary matrix with condition

functionmatrix

how i can put (-1) after and before any group of ones in matrix like this
before code A = [ 1 1 0 0 0 1 0 1 1
0 1 1 0 0 0 0 1 1
0 0 1 1 0 0 1 0 0 ]
after code A* = [ 1 1 -1 0 -1 1 -1 1 1
-1 1 1 -1 0 0 -1 1 1
0 -1 1 1 -1 -1 1 -1 -1 ]

Best Answer

A = [ 1 1 0 0 0 1 0 1 1
0 1 1 0 0 0 0 1 1
0 0 1 1 0 0 1 0 0 ]
for k=1:size(A,1);
id_before=strfind(A(k,:),[0 1])
id_after=strfind(A(k,:),[1 0])+1
A(k,[id_before id_after])=-1
end