?? incid2list.m
字號:
function [i,j,c] = incid2list(I,c)
%INCID2LIST Node-arc incidence matrix to arc list representation.
% IJC = incid2list(I,c)
% [i,j,c] = incid2list(I,c)
% I = m x n node-arc incidence matrix
% c = (optional) n-element vector of arc weights
% IJC = n x 2-3 matrix arc list [i j c], where
% i = n-element vector of arc tails nodes
% j = n-element vector of arc head nodes
%
% Transforms: I[i(k),k] = 1 -> i(k)
% I[j(k),k] = -sign(j(k)) -> j(k), where
% I[j(k),k] = -1 => j(k) > 0, for directed arc (i(k),j(k))
% = 1 => j(k) < 0, for undirected arc (i(k),j(k))
% = I[j(k),k] = 1 => i(k) = j(k) (self-loop)
%
% Examples:
% I = [1 -1 0
% -1 0 -1
% 0 1 1]
% c = [1 3 2]
% IJC = incid2list(I,c) % IJC = 1 2 1
% % 3 1 3
% % 3 2 2
%
% I = [1 1 0 % Symmetric arcs
% 1 0 1
% 0 1 1]
% IJC = incid2list(I,c) % IJC = 1 -2 1
% % 3 -1 3
% % 2 -3 2
%
% See also LIST2INCID
% Copyright (c) 1994-2006 by Michael G. Kay
% Matlog Version 9 13-Jan-2006 (http://www.ie.ncsu.edu/kay/matlog)
% Input Error Checking ****************************************************
error(nargchk(1,2,nargin))
if nargin < 2, c = []; else c = c(:); end
n = size(I,2);
arc = sum(I); % arc(i) == 0, 1, or 2 => directed, self-loop, or undirected
if any(any(abs(I(I~=0)) ~= 1)) | any(arc~=0 & arc~=1 & arc~=2) | ...
any(sum(abs(I)) < 1 | sum(abs(I)) > 2)
error('Invalid node-arc incidence matrix.')
elseif ~isempty(c) && length(c) ~= n
error('"c" must be am n-element vector.')
end
% End (Input Error Checking) **********************************************
i = zeros(n,1); j = zeros(n,1);
[k,a_] = find(I(:,arc==0) == 1);
i(arc==0) = k;
[k,a_] = find(I(:,arc==0) == -1);
j(arc==0) = k;
[k,a_] = find(I(:,arc==1) == 1);
i(arc==1) = k;
j(arc==1) = k;
[k,a_] = find(I(:,arc==2) == 1);
k = reshape(k,length(k)/2,2)'; k = k(:);
i(arc==2) = k(1:length(k)/2);
j(arc==2) = -k(length(k)/2 + 1:end);
if nargout == 1
if isempty(c), i = [i j]; else i = [i j c]; end
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -