Learn R Programming

excursions (version 2.4.1)

submesh.grid: Extract a part of a grid

Description

Extracts a part of a grid.

Usage

submesh.grid(z, grid = NULL)

Arguments

z

A matrix with values indicating which nodes that should be present in the submesh.

grid

A list with locations and dimensions of the grid.

Value

An inla.mesh object.

Examples

Run this code
# NOT RUN {
if (require(INLA)) {
nxy = 40
x=seq(from=0,to=4,length.out=nxy)
lattice=inla.mesh.lattice(x=x,y=x)
mesh=inla.mesh.create(lattice=lattice, extend=FALSE, refine=FALSE)

#extract a part of the mesh inside a circle
xy.in <- rowSums((mesh$loc[,1:2]-2)^2)<1
submesh <- submesh.grid(matrix(xy.in,nxy,nxy),
                        list(loc=mesh$loc,dim=c(nxy,nxy)))
plot(mesh$loc[,1:2])
lines(2+cos(seq(0,2*pi,length.out=100)), 2+sin(seq(0,2*pi,length.out=100)))
plot(submesh,add=TRUE)
points(mesh$loc[xy.in,1:2],col="2")
}
# }

Run the code above in your browser using DataLab