f



node-node adjacency matrix to a node-arc adjacency matrix

I have been trying to figure out how to create a arc-node adjacency matrix from a node-node adjacency matrix, for example:

node-node adj
A = [0 1 0 1 1;
     0 0 1 1 0;
     0 0 0 1 1;
     0 0 0 0 1;
     0 0 0 0 0];

looking for the following links: 1-2,1-4,1-5,2-3,2-4,3-4,3-5,4-5

arc-node adj
B =[ 1  1  1  0  0  0  0  0
    -1  0  0  1  1  0  0  0
     0  0  0 -1  0  1  1  0 
     0 -1  0  0 -1 -1  0  1
     0  0 -1  0  0  0 -1 -1];

Any help will be greatly appreciated: 
I have tried to develop a for loop using "A" and assigning -1 to the tail end of the link but with no success...



 
0
shhernan (17)
10/21/2008 12:24:02 AM
comp.soft-sys.matlab 211265 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
590 Views

Similar Articles

[PageSpeed] 11

"Sal " <shhernan@purdue.edu> wrote in message <gdj7f2$c62$1@fred.mathworks.com>...
> I have been trying to figure out how to create a arc-node adjacency matrix from a node-node adjacency matrix, for example:
> 
> node-node adj
> A = [0 1 0 1 1;
>      0 0 1 1 0;
>      0 0 0 1 1;
>      0 0 0 0 1;
>      0 0 0 0 0];
> 
> looking for the following links: 1-2,1-4,1-5,2-3,2-4,3-4,3-5,4-5
> 
> arc-node adj
> B =[ 1  1  1  0  0  0  0  0
>     -1  0  0  1  1  0  0  0
>      0  0  0 -1  0  1  1  0 
>      0 -1  0  0 -1 -1  0  1
>      0  0 -1  0  0  0 -1 -1];
> 
> Any help will be greatly appreciated: 
> I have tried to develop a for loop using "A" and assigning -1 to the tail end of the link but with no success...
> 
> 
> 
>  


This is my code:
 A = [0 1 0 1 1;
     0 0 1 1 0;
     0 0 0 1 1;
     0 0 0 0 1;
     0 0 0 0 0];
 
 [m n]=size(A); %size of A

sM = zeros(1,m);
sN = zeros(n+1,1);
As = A;

As(m+1,:) = sM;
As(:,n+1) = sN;
 
 
NZ=nonzeros(As);
Edc=length(NZ);
AtoN = zeros(m+1,Edc);

Arc=0;
for i=1:m+1
    [k,l]=find(Asink(i,:));
    aa=length(l);
    for j=1:aa
        AtoN(i,Arc+j) = -1;
        AtoN(l(1,j),Arc+j)=1;
    end
    Arc=Arc+aa;
end
disp(AtoN)
0
shhernan (17)
10/21/2008 1:25:04 AM
Hi,

I have written this piece a long time ago...

siz = size(A);

nrknots = siz(1);
nredges = nnz(A);
[IXknots1,IXknots2] = find(A);
sones = ones(nredges,1);
IXedges = (1:nredges)';

B = sparse([IXedges; IXedges],...
             [IXknots1; IXknots2],...
             [-sones; sones],...
             nredges,nrknots);

You might need to adapt it (transpose B, change the sign of the entries in B), but it should work.

HTH,
Wolfgang
0
10/21/2008 10:52:01 AM
Reply: