-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlenloc2sparse.m
40 lines (38 loc) · 1.09 KB
/
lenloc2sparse.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
function [sparseA] = lenloc2sparse(len,loc,resolution,thetaresolution,direction)
%LENLOC2SPARSE 此处显示有关此函数的摘要
% 函数把纵向(direction=2)横向(direction=1)压缩的变成稀疏矩阵
sparseAprepare=zeros(size(find(loc~=0),1),3);
mm=1;
if direction==1
for i=1:1:180/thetaresolution
for j=1:1:resolution
k=1;
while loc(i,j,k)~=0
sparseAprepare(mm,:)=[(i-1)*resolution+j,loc(i,j,k),len(i,j,k)];
k=k+1;
mm=mm+1;
end
end
end
else
for i=1:1:resolution
for j=1:1:resolution
ind=(i-1)*resolution+j;
k=1;
while loc(ind,k)~=0
sparseAprepare(mm,:)=[loc(ind,k),ind,len(ind,k)];
k=k+1;
mm=mm+1;
end
end
end
end
sparseAprepare=sparseAprepare(1:mm-1,:);
m=resolution*180/thetaresolution;
n=resolution*resolution;
try
sparseA=sparse(sparseAprepare(:,1),sparseAprepare(:,2),sparseAprepare(:,3),m,n);
catch ErrorInfo %捕获到的错误是一个MException对象
disp(ErrorInfo);
end
end