find_edges_2D | R Documentation |
Finds edges in an evenly spaced 2D grid.
c_search |
Logical vector |
n_col |
x direction of the matrix |
find_edges_2D
Checks all neighbour indices in a vector c_search
for TRUE
. If all neighbours are TRUE
it is not an edge, else it is.
logical vector if edge was found
n_col <- 7
n_row <- 4
c_search <- c(
0,1,0,0,0,1,0,
1,1,1,1,1,1,1,
0,1,0,1,1,1,1,
0,0,1,1,1,1,1
)
m_grid <- expand.grid(x = 0:(n_col-1), y = 0:(n_row-1))|>
as.matrix()|>
cbind(c_search)
m_grid|>
head()
m_grid|>
plot(col = m_grid[,"c_search"],
xlim=c(0,n_col-1), ylim=c(0,n_row-1),
pch = 19,
cex = 2.5,
main = "Input: c_search")
m_grid <- cbind(m_grid,
edge = find_edges_2D(m_grid[,"c_search"], n_col))
m_grid|>
head()
m_grid|>
plot(col = m_grid[,"edge"],
xlim=c(0,n_col-1), ylim=c(0,n_row-1),
pch = 19,
cex = 2.5,
main = "Edge")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.