-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add file for getting v2emat from new connectivity info
- Loading branch information
1 parent
cb5e2e4
commit 295dad0
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|