horizontal Transition code error index out of bounds anyone help!!!
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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?
Antworten (2)
Walter Roberson
am 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 Kommentare
priya
am 24 Mai 2012
Walter Roberson
am 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.)
priya
am 25 Mai 2012
1 Kommentar
Walter Roberson
am 25 Mai 2012
That code would miss the last row, i==r .
Diese Frage ist geschlossen.
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!