Skip to content

Commit

Permalink
add file for getting v2emat from new connectivity info
Browse files Browse the repository at this point in the history
  • Loading branch information
askhamwhat committed Mar 29, 2024
1 parent cb5e2e4 commit 295dad0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions chunkie/@chunkgraph/build_v2emat.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function A = build_v2emat(obj)
%V2EMAT get a "vertex to edge" matrix for the chunkgraph object
%
% input: obj - a chunkgraph object
%
% output: A - a nedges x nverts sparse matrix
% A(i,j) = 1 if edge i starts at vertex j
% A(i,j) = -1 if edge i ends at vertex j
% A(i,j) = 2 if edge i starts and ends at vertex j
%

nverts = size(obj.verts,2);
nedges = size(obj.edgesendverts,2);


ii = zeros(2*nedges,1);
jj = zeros(2*nedges,1);
vv = zeros(2*nedges,1);
nf = 0;

for i = 1:nedges
j1 = obj.edgesendverts(1,i);
j2 = obj.edgesendverts(2,i);
if j1 == j2
nf = nf + 1;
ii(nf) = i;
jj(nf) = j1;
vv(nf) = 2;
else
nf = nf + 1;
ii(nf) = i;
jj(nf) = j1;
vv(nf) = -1;
nf = nf + 1;
ii(nf) = i;
jj(nf) = j2;
vv(nf) = 1;
end
end

A = sparse(ii(1:nf),jj(1:nf),vv(1:nf),nedges,nverts);

0 comments on commit 295dad0

Please sign in to comment.