Info

此问题已关闭。 请重新打开它进行编辑或回答。

Error - Index exceeds matrix dimensions..?

1 次查看(过去 30 天)
Jhay
Jhay 2011-11-30
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Jhay
Jhay 2011-11-30
[y z] = size (row1)
which gives you,
y = 1
z = 2391

回答(3 个)

Walter Roberson
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) ?)

Jhay
Jhay 2011-11-30
Overlapping should not be there. Thanks for saying this.. And why should I take x = 1:500:z-500 since I need all the values till the end of the column??? But I need to access row1 x through x+499 and then combining all parts together finally..
[y z] = size (row1)
which gives you,
y = 1 z = 2391
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:x+499));
BW = 255 * im2bw((row1(1,x:x+499)),level);
end
v(1,x:x+499) = BW(1,x:x+499)
figure;
hold on
plot (row1);
plot (BW,'g')
hold off
  2 个评论
Walter Roberson
Walter Roberson 2011-11-30
Thinking again, z-500 is not needed after all.
Jhay
Jhay 2011-11-30
ya you are right.. z-100 is not at all needed...

Jhay
Jhay 2011-11-30
No I dint mean in the way you mentioned. HOw did you given the values for x roughly as 2001???
I have initiated a vector with zeros initially to the length of z (no. of columns) which is
v = zeros(1,z)
Now substituting the values of BW(1,x:x+499) in the respective places in the v(1,x:x+499)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by