Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.
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 -------> 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

share|improve this question
    
Your algorithm description is not really clear to me yet. For instance, why don't you start with 1 connect 3 (or 4...) instead of 1 connect 2. Does the matrix you are looking for have a name, and perhaps an article describing it? EDIT: Do you think an algorithm for the longest path could give you the desired outcome? –  Dennis Jaheruddin Feb 11 '13 at 13:01
    
it is also possible 1 connect to 3(or 4) instead 2. it can select anyone randomly but the node connected can not be connect again.i mean when a node it has been local then must be blocked. the first matrix(matrix one) is a undirected matrix and i want convert it to direct matrix but it must follow the rules i described –  doci Feb 11 '13 at 13:06
    
"EDIT: Do you think an algorithm for the longest path could give you the desired outcome?" yes it does.many thanks again Dennis –  doci Feb 11 '13 at 23:40
add comment

2 Answers

up vote 2 down vote accepted

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 && ~any(blocked == j)&& ~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
share|improve this answer
    
Note that i did not go for the most compact code but for what I hoped to be most easy to understand. –  Dennis Jaheruddin Feb 11 '13 at 16:44
    
It is what i wanted exactly it works great .Many thanks Dennis –  doci Feb 11 '13 at 17:52
    
Just to prevent confusion, this is not guaranteed to give you the longest path. It will just give you a path and keeps expanding it untill it cannot go further. –  Dennis Jaheruddin Feb 12 '13 at 9:21
add comment

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.

share|improve this answer
    
yes but as i mention in my program my number of nodes is N ,here is 10 only to gives a example. if you look carefully it is not something toward identity metrix! –  doci Feb 11 '13 at 13:43
    
The original matrix has full rank and the new matrix does not, so I think you are on the wrong track here. –  Dennis Jaheruddin Feb 11 '13 at 16:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.