[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to handle Matlab 'spconvert'?
From: |
John W. Eaton |
Subject: |
How to handle Matlab 'spconvert'? |
Date: |
Fri, 24 Apr 1998 01:06:05 -0500 (CDT) |
On 23-Apr-1998, Hans Zoebelein <address@hidden> wrote:
| There is a Matlab script file which loads a matrix A from an ASCII file
| and then does a AS = spconvert( A ). I hate to ask, but I didn't find
| help to handle this transformation under OCTAVE.
|
| How should I handle the 'spconvert' function under OCTAVE?
| Thx in advance.
Until Octave supports sparse matrices, here's a kluge. Obviously this
function will be worthless if your program really *needs* sparse
matrices.
jwe
## Copyright (C) 1998 John W. Eaton
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, write to the Free
## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.
## usage: spconvert (x)
##
## Convert 3 or 4 column matrices of the form
##
## [i, j, val] or [i, j, real, imag]
##
## to a full matrix (until Octave supports sparse matrices, this will
## have to do).
## Author: jwe
function retval = spconvert (x)
if (nargin != 1)
usage ("spconvert (x)");
endif
[nr, nc] = size (x)
if (nc == 3 || nc == 4)
sz = max (x);
retval = zeros (sz(1:2));
if (nc == 3)
for i = 1:nr
retval (x(i,1), x(i,2)) = x(i,3);
endfor
elseif (nc == 4)
for i = 1:nr
retval (x(i,1), x(i,2)) = x(i,3) + x(i,4) * __I__;
endfor
endif
else
error ("spconvert: argument must be a matrix with 3 or 4 columns");
endif
endfunction