Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/setdiag.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function M = setdiag(M, v) |
matthiasm@8 | 2 % SETDIAG Set the diagonal of a matrix to a specified scalar/vector. |
matthiasm@8 | 3 % M = set_diag(M, v) |
matthiasm@8 | 4 |
matthiasm@8 | 5 n = length(M); |
matthiasm@8 | 6 if length(v)==1 |
matthiasm@8 | 7 v = repmat(v, 1, n); |
matthiasm@8 | 8 end |
matthiasm@8 | 9 |
matthiasm@8 | 10 % e.g., for 3x3 matrix, elements are numbered |
matthiasm@8 | 11 % 1 4 7 |
matthiasm@8 | 12 % 2 5 8 |
matthiasm@8 | 13 % 3 6 9 |
matthiasm@8 | 14 % so diagnoal = [1 5 9] |
matthiasm@8 | 15 |
matthiasm@8 | 16 |
matthiasm@8 | 17 J = 1:n+1:n^2; |
matthiasm@8 | 18 M(J) = v; |
matthiasm@8 | 19 |
matthiasm@8 | 20 %M = triu(M,1) + tril(M,-1) + diag(v); |
matthiasm@8 | 21 |