Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

??? Subscript indices must either be real positive integers or logicals.

조회 수: 1 (최근 30일)
GIANT
GIANT 2014년 5월 17일
마감: MATLAB Answer Bot 2021년 8월 20일
i am new and doing 2d convolution but i am stuck at this error. here is the code:
function output_args = convo(img,k )
%user giant malik
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
%I = [1 2 3;
%4 5 6;
%7 8 9;];
%k = [0 0 0;
%0 1 0;
%0 0 0];
[r1 c1]= size(img);
[r2 c2]=size(k);
length = r1+(r2-1); % for creating new dimensiont
row = length; %
col = length;
a= (r2-1)/2; b= (c2-1)/2; % start value for calculating convultion
s= a*(-1)+1;
t=(b)*(-1)+1;
%disp(s);
output_args=zeros([row, col]);
z=s;w=t;
for x=0:length
for y=0:length
for s=s:a+1
% disp(s);
for t= t:b+1
output_args(x,y)=output_args(x,y) + (output_args(s, t)* f(z-s,w-t)); % error pointing here
end
end
w=w+1;
end
z=z+1;
end
end

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 17일
In your code there are indices equal to 0.
output_args(x,y) % with x starting at 0 will give you an error, you should start at 1
  댓글 수: 1
GIANT
GIANT 2014년 5월 17일
i have intialise all with 1 but now its giving "??? Undefined function or method 'f' for input arguments of type 'double'." can u tell me how shell i intialise "f"?

Image Analyst
Image Analyst 2014년 5월 17일
Lots of problems with that code. No checking for number of dimensions of img. No initialization of output_args. No try/catch. Virtually no comments. No definition of the "f" function, Etc.
What happens if someone passes in a color image for img? Kaboom! Why? See this http://blogs.mathworks.com/steve/2011/03/22/too-much-information-about-the-size-function/
Put a try/catch into your function:
try
% Some code that might generate an error.
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
Move this to be first line, right after, or even right before, the try line:
output_args = [];
Now, .... the main reason for your error is that you used f, which is undefined . You're not really programming up a convolution correctly. Think about what indexes you should use. Perhaps it would be easier for you to extract a little sub-image from the main image, which is right under your sliding kernel window. Adding some comment before each line might help you figure out where you're going wrong. Give it a try and if you can't figure it out, let me know.
  댓글 수: 1
Image Analyst
Image Analyst 2014년 5월 17일
By the way, why not simply use conv2() or imfilter()???

제품

Community Treasure Hunt

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

Start Hunting!

Translated by