5164
|
1 ## Copyright (C) 2004 David Bateman & Andy Adler |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
5307
|
15 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
16 ## 02110-1301 USA |
5164
|
17 |
|
18 ## -*- texinfo -*- |
|
19 ## @deftypefn {Function File} {@var{x} =} spconvert (@var{m}) |
|
20 ## This function converts for a simple sparse matrix format easily |
|
21 ## produced by other programs into Octave's internal sparse format. The |
|
22 ## input @var{x} is either a 3 or 4 column real matrix, containing |
|
23 ## the row, column, real and imaginary parts of the elements of the |
|
24 ## sparse matrix. An element with a zero real and imaginay part can |
|
25 ## be used to force a particular matrix size. |
|
26 ## @end deftypefn |
|
27 |
|
28 function s = spconvert (m) |
|
29 |
|
30 if issparse(m) |
|
31 s = m; |
|
32 else |
|
33 sz = size(m); |
|
34 if (nargin != 1 || !ismatrix(m) || !isreal(m) || length(sz) != 2 || |
|
35 (sz(2) != 3 && sz(2) != 4)) |
|
36 error ("spconvert: input matrix must be either sparse or a three or four column"); |
|
37 error (" real matrix"); |
|
38 elseif (sz(2) == 3) |
|
39 s = sparse (m(:,1), m(:,2), m(:,3)); |
|
40 else |
|
41 s = sparse (m(:,1), m(:,2), m(:,3) + 1i*m(:,4)); |
|
42 endif |
|
43 endif |
|
44 endfunction |