comparison scripts/sparse/spconvert.m @ 5164:57077d0ddc8e

[project @ 2005-02-25 19:55:24 by jwe]
author jwe
date Fri, 25 Feb 2005 19:55:28 +0000
parents
children 4c8a2e4e0717
comparison
equal deleted inserted replaced
5163:9f3299378193 5164:57077d0ddc8e
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
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {@var{x} =} spconvert (@var{m})
19 ## This function converts for a simple sparse matrix format easily
20 ## produced by other programs into Octave's internal sparse format. The
21 ## input @var{x} is either a 3 or 4 column real matrix, containing
22 ## the row, column, real and imaginary parts of the elements of the
23 ## sparse matrix. An element with a zero real and imaginay part can
24 ## be used to force a particular matrix size.
25 ## @end deftypefn
26
27 function s = spconvert (m)
28
29 if issparse(m)
30 s = m;
31 else
32 sz = size(m);
33 if (nargin != 1 || !ismatrix(m) || !isreal(m) || length(sz) != 2 ||
34 (sz(2) != 3 && sz(2) != 4))
35 error ("spconvert: input matrix must be either sparse or a three or four column");
36 error (" real matrix");
37 elseif (sz(2) == 3)
38 s = sparse (m(:,1), m(:,2), m(:,3));
39 else
40 s = sparse (m(:,1), m(:,2), m(:,3) + 1i*m(:,4));
41 endif
42 endif
43 endfunction