Cody

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

76.47% Correct | 23.53% Incorrect
Last solution submitted on Feb 11, 2015

Problem Comments

Solution Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more