Error - Index exceeds matrix dimensions..?
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Im supposed to do the thresholding for a single row in an image spliting in to 5parts seperately and once it is done Im supposed to plot the all the parts together. when I run this prog, it shows Index exceeds matrix demension.... what am i supposed to do and where am I supposed to alter the code?? Somebody help me... Thank you......
I = imread('D:\1st Semester\Image analysis project\particles.tif');
B= fspecial('motion',33);
C= imfilter (I,B,'symmetric');
row1 = C(500,:);
[y z] = size (row1);
v = zeros(1,z)
for x = 1:500:z;
level = graythresh(row1(1,x) : row1(1,x+500));
BW = 255 * im2bw((row1(1,x) : row1(1,x+500)),level);
end
v(1,x:x+500) = BW(1,x:x+500)
figure;
hold on
plot (row1);
plot (BW,'g')
hold off
2 comentarios
Chandra Kurniawan
el 30 de Nov. de 2011
What are the size of I?
Jhay
el 30 de Nov. de 2011
Respuestas (3)
Walter Roberson
el 30 de Nov. de 2011
Your line
for x = 1:500:z
should be
for x = 1:500:z-500
Your z is the number of columns in row1, so with your original code x could be as high as the number of columns, but you then try to index the array up to column x+500
By the way: are you sure you want to be doing overlapping calculations? x = 1 the first time, so you access up to row1(1,1+500), which is row1(1,501) . Then the second time through the loop, x = 501, and you access 501 through 1001 which duplicates the access at 501.
I would suggest that you also consider whether you want to be creating vectors whose length depend upon the contents of the row. row1(1,x):row1(1,x+500) does not access row1 x through x+500: instead it looks into row1(1,x) and looks into row1(x,x+500) and uses those as the bounds for the ":" operator. Perhaps you instead want row1(1,x:x+500) ? (or, more likely, row1(1,x:x+499) ?)
Jhay
el 30 de Nov. de 2011
2 comentarios
Walter Roberson
el 30 de Nov. de 2011
Thinking again, z-500 is not needed after all.
Jhay
el 30 de Nov. de 2011
Jhay
el 30 de Nov. de 2011
0 votos
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!