Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
GIANT
GIANT le 17 Mai 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 17 Mai 2014
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 commentaire
GIANT
GIANT le 17 Mai 2014
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 le 17 Mai 2014
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 commentaire
Image Analyst
Image Analyst le 17 Mai 2014
By the way, why not simply use conv2() or imfilter()???

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by