Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
horizontal Transition code error index out of bounds anyone help!!!
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
horizontal transition:
horizontal scanning thro block and finds no of times pixel value change state from 0 to 1 or 1 to 0
my coding :
[r c]=size(g);
for i=1:r-1
for j=1:c-1;
if(j==c)
break;
elseif g(i,j)==0 && g(i,j+1)==1
c=c+1;
end
end
end
disp(c);
and error is
Attempted to access g(213,1118); index out of bounds because size(g)=[1537,1117].
Error in ==> ht at 8
elseif g(i,j)==0 && g(i,j+1)==1
can anyone help to solve dis pls?
0 commentaires
Réponses (2)
Walter Roberson
le 24 Mai 2012
You could encounter that error if g has more than 2 dimensions.
By definition, if you use two output arguments, then
[r c] = size(g)
would be the same as
t = size(g);
r = t(1);
c = prod(t(2:end))
If for example, you had a 10 x 10 x 3 g matrix, then [r c] = size(g) would be r=10 and c=10*3
Of course other parts of your code are likely to have logical problems if g has more than 2 dimensions, but this size() problem is the way that you end up with the second dimension being out of range.
2 commentaires
Walter Roberson
le 24 Mai 2012
Please show us the values of r and c as known to your program (that is, put in a breakpoint and see what the _program_ thinks they are.)
Cette question est clôturée.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!