An efficient way to create a 2D array.

Hey everyone, I am new to matlab. Here is my question:
Suppose, I = [a b c d e; f g h i j; k l m n o; p q r s t];
If (I(current pixel) == I(neighbour pixel)) then E(current pixel,neighbor pixel) = 1; else E(current pixel, neighbor pixel) = 0;
whereas a neighbor pixel is any pixel in 3x3 window centered at the current pixel. (I think this convention is know as the 8-neighbor)
One possible way is to use doubly nested for loop. Is there any more efficient way (using any of these (<http://www.mathworks.com/help/matlab/elementary-matrices-and-arrays.html>) data structure) and please write a hint how to use it since I cannot figure it out by myself.

2 Comments

who do you consider the neighbour pixel(s)? Only the pixel next to the current pixel (left, right, both) ?
David Sanchez
I have edited the question statement. I am taking 8-neighbors convention.

Sign in to comment.

Answers (0)

Categories

Asked:

on 20 Jun 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!