-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsparse2alist.m
49 lines (36 loc) · 880 Bytes
/
sparse2alist.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function sparse2alist(H,filename)
A = full(H);
M = size(A,1);
N = size(A,2);
ratebyrows = zeros(M,1);
ratebycols = zeros(N,1);
for i = 1:M
rateinrow = find(A(i,:));
ratebyrows(i) = size(rateinrow,2);
end
for i = 1:N
rateincol = find(A(:,i));
ratebycols(i) = size(rateincol,1);
end
maxinrows = max(ratebyrows);
maxincols = max(ratebycols);
fID = fopen(filename, 'w');
fprintf(fID,'%d\t', N, M);
fprintf(fID,'\n');
fprintf(fID,'%d\t', maxincols, maxinrows);
fprintf(fID,'\n');
fprintf(fID,'%d\t', ratebycols);
fprintf(fID,'\n');
fprintf(fID,'%d\t', ratebyrows);
fprintf(fID,'\n');
for i = 1:N
rateincol = find(A(:,i));
fprintf(fID,'%d\t', rateincol);
fprintf(fID,'\n');
end
for i = 1:M
rateinrow = find(A(i,:));
fprintf(fID,'%d\t', rateinrow);
fprintf(fID,'\n');
end
fclose(fID);