Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Error - Index exceeds matrix dimensions..?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (3개)
Walter Roberson
2011년 11월 30일
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) ?)
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!