Does this matrix function exist


observations = rows
variables = columns

Connected matrix:

[ 1 0 0 -1]
[ 1 1 0  0]
[ 1 0 1  0]
[ 0 0 1  1]

all variables are connected to all other variables (by some path)

A. 1st is connected to 4th
B. 1st is connected to 2nd
C. 1st is connected to 3th
D. 3rd is connected to 4th

by A. and D., 1st is connected to 4th

———————-

Non-connected matrix:

[ 1 0  4 0]
[ 0 6  0 7]
[ 0 -2 0 3]
[ 5 0 -2 0]

Variables 1 and 3 are connected (by observations 1 and 4)
Variables 2 and 4 are connected (by observations 2 and 3)

Can be separated into two matrices:

[1  4]
[5 -2]

[ 6 7]
[-2 3]

———————-

I would like a function that would return the connectedness of variables (columns)

For 1st matrix, function would return [ 1 1 1 1], all variables are connected.
For 2nd matrix, function would return [ 1 2 1 2], variables 1 and 3 are connected, variables 2 and 4 are connected .

Does this type of function exist?


One response to “Does this matrix function exist”

  1. This is the function I made. If you have an improvement, please contact me.

    ————————

    function pool = connects(x)

    pool = zeros(1,size(x,2));
    PoolCount = 0;

    %
    % Check connections between variables (columns)
    %

    for i = 1:size(x,2)

    if pool(i) == 0
    % column has not yet been examined
    PoolCount = PoolCount + 1;
    pool(i) = PoolCount;
    ConnectedSet = zeros(size(x,2));
    ConnectedSet(1) = [i];
    ConnectedCount = 1;

    count2 = 1;
    while (count2 <= ConnectedCount) % find rows that have non-zero entries in column i rows = find(x(:,ConnectedSet(count2)) ~= 0); %%%rows for k = 1:length(rows) k = rows(k); new1 = setdiff(find(x(k,:) ~= 0),ConnectedSet(1:ConnectedCount)); ConnectedSet(ConnectedCount+1:ConnectedCount+length(new1)) = new1'; ConnectedCount = length(new1)+ConnectedCount; end count2 = count2 + 1; end pool(ConnectedSet(1:ConnectedCount)) = PoolCount; end end clear i count2 k ConnectedCount ConnectedSet PoolCount; endfunction;