Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
med-sweng
med-sweng le 4 Mar 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
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.

Réponses (1)

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

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by