How can i convert the matrix 1 to matrix 2? A= 0 1 1 1 1 1 1 1 1 1          0 1 0 0 0 0 0 0 0 0  
   1 0 1 1 1 1 1 1 1 1          0 0 1 0 0 0 0 0 0 0
   1 1 0 1 1 1 0 1 1 1          0 0 0 1 0 0 0 0 0 0
   1 1 1 0 1 1 1 0 0 0 -------&gt; 0 0 0 0 1 0 0 0 0 0
   1 1 1 1 0 1 1 0 0 0          0 0 0 0 0 1 0 0 0 0
   1 1 1 1 1 0 0 1 1 0          0 0 0 0 0 0 0 1 0 0
   1 1 0 1 1 0 0 1 1 1          0 0 0 0 0 0 0 0 1 0
   1 1 1 0 0 0 1 0 1 1          0 0 0 0 0 0 1 0 0 0 
   1 1 1 0 0 1 1 1 0 1          0 0 0 0 0 0 0 0 0 1  
   1 1 1 0 0 1 1 1 1 0          0 0 0 0 0 0 0 0 0 0 


Here a Boolean matrix let call it A matrix and A(NxN) and here N=10. 0 mean there is no connection between nodes(as it can be seen there is no self connection also) and 1 means there is connection between nodes.

Here the first local node is node1 and when a node is local then must be blocked so can not be selected (connected) again

    Node 1 connect  node 2, then node 2 is local (must be blocked)
    2 connect 3, now 3 is local (must be blocked)
    3 connect 4, 4 is local (must be blocked)
    4 connect 5, 5 is local (must be blocked)   
    5 connect 6 ,6 is local (must be blocked)
    6 connect 8, 8 is local (must be blocked)
    8 connect 7, 7 is local (must be blocked)
    7 connect 9, 9 is local (must be blocked)
    9 connect 10,10 is local and stop here as all number are local.here 10 can not connect 1 about one was local


After connections matrix should be as the matrix at the end of figure.
How can i write it in matlab
Here is one way to make the matrix you describe, without further details i cannot see if it really matches what you are looking for but you should be able to edit it yourself.

%Set things for the start:
i = 1;
blocked = 1;
used = [];
B = zeros(size(A));
for i = 1:size(A,1)
    for j = 1:size(A,2)
        % Test if node i can be connected with node j 
        if A(i,j) == 1 &amp;&amp; ~any(blocked == j)&amp;&amp; ~any(used == i)
            % Connect node i with node j
            B(i,j) = 1;
            % Block node j
            blocked = [blocked j];
            % To make sure we only have one entry per row
            used = [used i];
        end
    end
end
You must apply some of the method to find the rank of the matrix either row exchange or column exchange method, after few steps your upper part will be just converging towards identity metrix of six order. Then manipulate for the last three rows.