matrixSmooth: Smooth a Matrix

Description Usage Arguments Value Author(s) Examples

Description

The values on the edge of the matrix are unaltered. For interior points, the result is defined in terms in terms of the original as follows. r_[i,j] = (2 m_[i,j] + m_[i-1,j] + m_[i+1,j] + m_[i,j-1] + m_[i,j+1])/6. Note that missing values propagate to neighbours.

Usage

1
matrixSmooth(m, passes = 1)

Arguments

m

a matrix to be smoothed.

passes

an integer specifying the number of times the smoothing is to be applied.

Value

A smoothed matrix.

Author(s)

Dan Kelley

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(oce)
opar <- par(no.readonly = TRUE)
m <- matrix(rep(seq(0, 1, length.out=5), 5), nrow=5, byrow=TRUE)
m[3, 3] <- 2
m1 <- matrixSmooth(m)
m2 <- matrixSmooth(m1)
m3 <- matrixSmooth(m2)
par(mfrow=c(2, 2))
image(m,  col=rainbow(100), zlim=c(0, 4), main="original image")
image(m1, col=rainbow(100), zlim=c(0, 4), main="smoothed 1 time")
image(m2, col=rainbow(100), zlim=c(0, 4), main="smoothed 2 times")
image(m3, col=rainbow(100), zlim=c(0, 4), main="smoothed 3 times")
par(opar)

Example output

Loading required package: testthat
Loading required package: gsw
pass=1
pass=1
pass=1

oce documentation built on March 28, 2021, 9:09 a.m.