Skip to content

Commit 5897b29

Browse files
committed
Make compatible with 1D input
1 parent d17243d commit 5897b29

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

spInd2SpSub.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
function subsA = spInd2SpSub(spA)
2-
%SPIND2SPSUB Convert a sparse array's linear index into a matrix of subscripts.
2+
%SPIND2SPSUB Convert a sparse array's linear index into a matrix of subscripts.
33
%
44
% subsA = spInd2spSub(spA)
55
%
66
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
7-
%
7+
%
88
% See also spSub2SpInd, spSub4Sp, ind2sub, sub2ind.
99

1010
% Convert spA's linear index to subscripts
1111
nDimA = numel(spA.Size);
12-
cellSubA = cell(1,nDimA); % create empty cell for next line
13-
[cellSubA{:}] = ind2sub(spA.Size,spA.Ind);
14-
subsA = [cellSubA{:}];
12+
if nDimA == 1
13+
subsA = spA.Ind;
14+
else
15+
cellSubA = cell(1,nDimA); % create empty cell for next line
16+
[cellSubA{:}] = ind2sub(spA.Size,spA.Ind);
17+
subsA = [cellSubA{:}];
18+
end
1519

1620
end
1721

0 commit comments

Comments
 (0)