Mercurial > matrix-functions
view matrixcomp/sparsify.m @ 7:e0817ccb2834 draft
Add square root matrix function file, rename atom at funm_files, modify old toolbox to run it inside GNU Octave.
added funm_files/fun_atom.m
added sqrtm2.m
added toolbox/gecp.m
toolbox/see.m: comment wrong call to subplot
toolbox/tmtdemo.m: add a cast to double, as eig does not admit bool matrix input
removed funm_files/funm_atom.m
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Tue, 26 May 2015 18:14:54 +0200 |
parents | 8f23314345f4 |
children |
line wrap: on
line source
function A = sparsify(A, p) %SPARSIFY Randomly set matrix elements to zero. % S = SPARSIFY(A, P) is A with elements randomly set to zero % (S = S' if A is square and A = A', i.e. symmetry is preserved). % Each element has probability P of being zeroed. % Thus on average 100*P percent of the elements of A will be zeroed. % Default: P = 0.25. if nargin < 2, p = 0.25; end if p<0 | p>1, error('Second parameter must be between 0 and 1 inclusive.'), end [m,n] = size(A); if ~isequal(A,A') A = A .* (rand(m,n) > p); % Unsymmetric case else A = triu(A,1) .* (rand(m,n) > p); % Preserve symmetry A = A + A'; A = A + diag( diag(A) .* (rand(size(n,1)) > p) ); end