-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathalist2sparse.m
42 lines (36 loc) · 1.09 KB
/
alist2sparse.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
function [H] = alist2sparse(fname)
% reads binary parity check matrix in "alist" format from file FNAME and
% converts it to sparse matrix used in MATLAB routines.
% This is an interface to matrices at http://wol.ra.phy.cam.ac.uk/mackay/codes/
%
% Example
% [H] = alist2sparse('A'); % A is the ascii file in alist format
% Copyright (c) 1999 by Igor Kozintsev [email protected]
% $Revision: 1.1 $ $Date: 2000/03/23 $ Bug fixed by Hatim Behairy
fid = fopen(fname);
n = fscanf(fid,'%d',1);
m = fscanf(fid,'%d',1);
maxinrow = fscanf(fid,'%d',1);
junk = fscanf(fid,'%d',1); % no need
num = fscanf(fid,'%d',[1 n]); % number of elements in rows
num2(1:n)=maxinrow;
junk = fscanf(fid,'%d',[1 m]); % no need
position = zeros(n,maxinrow);
for i=1:n
for j=1:num2(i)
position(i,j) = fscanf(fid,'%d',1);
end
end
ii = zeros(1,sum(num));
jj = ii;
k = 1;
for i=1:n
for j=1:num(i)
jj(k) = i;
ii(k) = position(i,j);
ss = 1;
k = k+1 ;
end
end
H = sparse(ii,jj,ss,m,n);
fclose(fid);