powered by
F matrices utility function.
replaceBand(a, b, k)
A matrix (same size as a)
The matrix to be replaced
The matrix with the replacement values
The extend of the replacement: 0 (diagonal only), 1 (diagonal and first extra diagonal), in general an entry is replaced if abs(row(a) - col(a)) <= k
Bertrand Frederic, Myriam Maumy-Bertrand.
a=matrix(1:9,3,3) b=matrix(0,3,3) replaceBand(a,b,0) replaceBand(a,b,1) replaceBand(a,b,2)
Run the code above in your browser using DataLab