problem with subscript indices and varibles in functions
조회 수: 2 (최근 30일)
이전 댓글 표시
If I use the following code:
function image_processing_project
M = imread('C:\Users\bostock_h\Documents\Images\130510_162.jpg');
M = int16(M);
x = 975; %dimensions of the image
y = 1010;
sum=0;
global steps %the number of steps taken for the average
steps = 12;
global lowlimit %minimum value to pass
lowlimit = 40;
global highlimit %maximum value to pass
highlimit = 200;
global movel %amount of pixels moved to the left after check
movel = 10;
prog = 0;
pixelnum = (x - movel - 1)*y; %Total number of pixels in the image
%Main loop begin
for j = 1:y
for i1 = movel + 1:x
c = checkright (i1,j);
if c ~= 0
b = 1;
else
b = -1;
end
if c == 0
c = checkleft (i1,j);
end
if c == -1
if b == 1
M(j,i1-movel) = 1;
end
end
if c == 1
if b == 1
M(j,i1-movel) = 250;
end
end
if c == 1
if b == -1
M(j,i1+movel) = 250;
end
end
if c == -1
if b == -1
M(j,i1+movel) = 1;
end
end
prog = prog + 1;
percent = (prog / pixelnum) * 100
end
end
imagesc(M)
colormap(gray)
function c = checkright(i1,j)
x1 = 1;
c = checkhorizontal(i1,j,x1);
end
function c = checkleft(i1,j)
x1 = -1;
c = checkhorizontal(i1,j,x1);
end
function c = checkhorizontal(i1,j,x1)
for n = 0:steps
sum = M(j, i1 + n*x1) + sum;
end
avg = sum / steps;
if avg < lowlimit
c = -1*x1;
else c = 0;
end
if avg > highlimit
c = 1*x1;
else c = 0;
end
end
end
Then I am given the following error message:
Subscript indices must either be real positive integers or logicals.
Error in image_processing_project/checkhorizontal (line 75)
sum = M(j, i1 + n*x1) + sum;
Error in image_processing_project/checkleft (line 70)
c = checkhorizontal(i1,j,x1);
Error in image_processing_project (line 31)
c = checkleft (i1,j);
댓글 수: 0
채택된 답변
Walter Roberson
2013년 6월 25일
When i1 is -1 and n is 0, i1 + n*x1 becomes -1, which is not a valid subscript.
댓글 수: 0
추가 답변 (1개)
David Sanchez
2013년 6월 25일
It is just that what the error message says, you are trying to access the image with a non integer index. Check your indexes out and you sort out your problems.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!