-
Notifications
You must be signed in to change notification settings - Fork 9
/
METqc2sparse.m
42 lines (37 loc) · 1.13 KB
/
METqc2sparse.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, n, m, z] = METqc2sparse(qcHFileName)
fid = fopen(qcHFileName, "r");
n = fscanf(fid, "%d", [1 1]);
m = fscanf(fid, "%d", [1 1]);
z = fscanf(fid, "%d", [1 1]);
I = sparse(eye(z));
Z = sparse(zeros(z));
H = sparse([]);
for i = 1:m
lH = sparse([]);
for j = 1:n
shiftList = [];
shift = fscanf(fid, "%d", [1 1]);
% Recursively read shift2 values until a empty is encountered
while true
shift2 = fscanf(fid, "&%d", [1 1]);
if isempty(shift2)
break;
end
shiftList = [shiftList, shift2];
end
if shift == -1
lH = [lH Z];
else
lH = [lH, getCircshiftSum(I, shift, shiftList)];
end
end
H = [H; lH];
end
fclose(fid);
end
function lH = getCircshiftSum(I, shift, shiftList)
lH = circshift(I, [0 shift]);
for k = 1:length(shiftList)
lH = lH + circshift(I, [0 shiftList(k)]);
end
end