Mercurial > hg > octave-avbm
changeset 1083:fb8ca633c439
[project @ 1995-01-28 19:24:32 by jwe]
author | jwe |
---|---|
date | Sat, 28 Jan 1995 19:24:45 +0000 |
parents | d1a1608f1028 |
children | 9c1511bfda68 |
files | scripts/general/tril.m scripts/general/triu.m |
diffstat | 2 files changed, 10 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/tril.m +++ b/scripts/general/tril.m @@ -27,24 +27,22 @@ if (nargin > 0) [nr, nc] = size (x); - retval = x; + retval = zeros (nr, nc); endif if (nargin == 1) k = 0; elseif (nargin == 2) - max_nr_nc = max (nr, nc); - if ((k > 0 && k > nr - 1) || (k < 0 && k < 1 - nc)) + if ((k > 0 && k > nc) || (k < 0 && k < -nr)) error ("tril: requested diagonal out of range") endif else usage ("tril (x [, k])"); endif - for i = 1:nr - for j = i+1-k:nc - retval (i, j) = 0.0; - endfor + for j = 1 : min (nc, nc + abs (k)) + nr_limit = max (1, j-k); + retval (nr_limit:nr, j) = x (nr_limit:nr, j); endfor endfunction
--- a/scripts/general/triu.m +++ b/scripts/general/triu.m @@ -27,24 +27,22 @@ if (nargin > 0) [nr, nc] = size (x); - retval = x; + retval = zeros (nr, nc); endif if (nargin == 1) k = 0; elseif (nargin == 2) - max_nr_nc = max (nr, nc); - if ((k > 0 && k > nc - 1) || (k < 0 && k < 1 - nr)) + if ((k > 0 && k > nc) || (k < 0 && k < -nr)) error ("triu: requested diagonal out of range") endif else usage ("triu (x [, k])"); endif - for j = 1:nc - for i = j+1-k:nr - retval (i, j) = 0.0; - endfor + for j = max (1, k) : nc + nr_limit = min (nr, j-k); + retval (1:nr_limit, j) = x (1:nr_limit, j); endfor endfunction