Problem 1961. Finding neighbors of [-1:1] in a matrix....
Hello All!
Well I found this one fun to figure out, all you have to do is make a matrix of 1's or 0's (true or false) that show whether or not a number in a matrix is sitting directly next to (a neighbor) that is number that is +1 or -1 or == to that of the original number. Here are some examples:
M1 = [1 2 1; 5 6 7; 2 3 6]
SO now find numbers next to one another that are +1 of each-other.
output = [1 1 1; 1 1 1; 1 1 1] One more:
M2 = [8 8 8; 4 4 4; 1 9 7]
SO now find numbers next to one another that are +1 of each-other.
output = [1 1 1; 1 1 1; 0 0 0]
One more:
M3 = [1 8 5; 4 10 22; 1 66 7]
SO now find numbers next to one another that are +1 of each-other.
output = [0 0 0; 0 0 0; 0 0 0]
Well good luck!
Solution Stats
Problem Comments
-
1 Comment
Jean-Marie Sainthillier
on 7 Mar 2014
Good problem. You should generalise it with more tests (size of the matrix, different gap...).
I suspect that my solution isn't correct.
Solution Comments
Show commentsGroup

Indexing III
- 23 Problems
- 44 Finishers
- expand intervals vol.3
- remove single elements
- return row and column indices given 2 values which define a range
- expand intervals vol.2
- compress sequence into intervals
- expand intervals
- Max Change in Consecutive Elements
- remove single elements
- Back to basics - mean of corner elements of a matrix
- Time Expansion
- Three...is a magic number.
- counting groups!
- Largest territory
- Replace pattern 0 1 0 and 1 0 1
- Find the index of n in magic(n)
- Sum of odd numbers in a matrix
- return row and column indices given 2 values which define a range
- Another colon problem
- How unique?
- Finding neighbors of [-1:1] in a matrix....
- Find the maximum two numbers of every column of a matrix
- Index one element in each vector of an array along a given dimension
- Tridiagonal
- Index of a Rational number
- Sort numbers by outside digits
Problem Recent Solvers78
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!