-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspTol.m
More file actions
24 lines (19 loc) · 691 Bytes
/
spTol.m
File metadata and controls
24 lines (19 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function spC = spTol(spA,tol)
%SPTOL Make all entries with magnitudes smaller than 'tol' equal to zero.
%
% spC = spTol(spA,tol): Make all entries of a full array (represented as a
% sparse array structure or a full array) with magnitudes no greater than
% 'tol' equal to zero. The output is a sparse array structure.
%
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
%
% See also SPTRUNC.
% If full array, convert to sparse array structure
if ~isstruct(spA)
spA = array2SpArray(spA);
end
indA = spA.Ind(abs(spA.Val-0)>tol);
valA = spA.Val(abs(spA.Val-0)>tol);
% Make the sparse aray structure
spC = struct('Size',spA.Size,'Ind',indA,'Val',valA);
end