Permalink
Browse files

updated for general radius

  • Loading branch information...
1 parent 859af52 commit 67033dda3f3f7e94d6543d0df0b824442c85a339 @cboettig committed Jul 17, 2013
Showing with 57 additions and 3 deletions.
  1. +21 −1 moore.Rmd
  2. +36 −2 moore.md
View
@@ -42,6 +42,26 @@ wrapped_neighborhood[,2] <- (neighborhood[,2] - 1) %% dim(M)[2] + 1
Clearly this can be extended to $r > 1$.
+```
+r_max <- 3
+rows <- numeric(0)
+cols <- numeric(0)
+
+for(r in 1:r_max){
+ rows <- c(rows, c(i-r, i, i+r, i-r, i, i+r, i-r, i, i+r))
+ cols <- c(cols, c(j-r, j-r, j-r, j, j, j, j+r, j+r, j+r))
+}
+
+neighborhood <- cbind(rows, cols)
+```
+
+Once again we have to deal with boundary cases, e.g. wrapping as before:
+
+```{r}
+wrapped_neighborhood <- neighborhood
+wrapped_neighborhood[,1] <- (neighborhood[,1] - 1) %% dim(M)[1] + 1
+wrapped_neighborhood[,2] <- (neighborhood[,2] - 1) %% dim(M)[2] + 1
+
+
-neighborhood
View
@@ -36,7 +36,7 @@ matrix(M[neighborhood], nrow = 3)
```
```
-## Error: subscript out of bounds
+## Error: object 'neighborhood' not found
```
@@ -45,14 +45,48 @@ matrix(M[neighborhood], nrow = 3)
```r
wrapped_neighborhood <- neighborhood
+```
+
+```
+## Error: object 'neighborhood' not found
+```
+
+```r
wrapped_neighborhood[, 1] <- (neighborhood[, 1] - 1)%%dim(M)[1] + 1
+```
+
+```
+## Error: object 'neighborhood' not found
+```
+
+```r
wrapped_neighborhood[, 2] <- (neighborhood[, 2] - 1)%%dim(M)[2] + 1
```
+```
+## Error: object 'neighborhood' not found
+```
+
Clearly this can be extended to $r > 1$.
+```
+r_max <- 3
+rows <- numeric(0)
+cols <- numeric(0)
+
+for(r in 1:r_max){
+ rows <- c(rows, c(i-r, i, i+r, i-r, i, i+r, i-r, i, i+r))
+ cols <- c(cols, c(j-r, j-r, j-r, j, j, j, j+r, j+r, j+r))
+}
+
+neighborhood <- cbind(rows, cols)
+```
+
+
+
+
+
-neighborhood

0 comments on commit 67033dd

Please sign in to comment.