Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Attempted to access pixels(0,1); index must be a positive integer or logical

1 view (last 30 days)
I'm trying to check the 3x3 neighbourhood for some pixel. For that, I did the following:
neighbour_F(1) = pixels(i-1,j-1);
neighbour_F(2) = pixels(i-1,j);
neighbour_F(3) = pixels(i-1,j+1);
neighbour_F(4) = pixels(i,j-1);
neighbour_F(6) = pixels(i,j+1);
neighbour_F(7) = pixels(i+1,j-1);
neighbour_F(8) = pixels(i+1,j);
neighbour_F(9) = pixels(i+1,j+1);
When I ran the code, I got the following error:
Attempted to access pixels(0,1); index must be a positive integer or logical.
Error in similarity (line 40)
neighbour_F(2) = pixels(i-1,j);
Yes, I know that this is since we will get a negative value for "i".
What can be done to avoid such error? I thought of adding if-statements, but, for instance, if I had to do "if i>1" twice (for two different neighbourhoods), will it just enter one of those if-blocks? As, I want to retrieve the value of all the neighbourhoods above.
Thanks.

Answers (1)

Image Analyst
Image Analyst on 4 Mar 2014
There is no zeoreth row of a matrix. The first (top) row is number 1, not 0.

This question is closed.

Community Treasure Hunt

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

Start Hunting!