Clear Filters
Clear Filters

Cant seem understand the error in code

2 views (last 30 days)
Divya
Divya on 22 Aug 2023
Answered: Dyuman Joshi on 22 Aug 2023
%%convolution
for i=1:size(I,1)-M %This line of code gives error as "At least one END is missing. The statement beginning here does not have a matching end."
for j=1:size(I,2)-N
Temp=I(i:i+M,j:j+M).*Kernel;% Multiply kernel with original image
Output(i,j)=sum(Temp(:));
end
Output=uint8(Output);
figure, imshow(Output);
Pl help

Answers (2)

Walter Roberson
Walter Roberson on 22 Aug 2023
You have an end statement corresponding to for j but you do not have an end statement corresponding to for i
I suspect you want
%%convolution
for i=1:size(I,1)-M
for j=1:size(I,2)-N
Temp=I(i:i+M,j:j+M).*Kernel;% Multiply kernel with original image
Output(i,j)=sum(Temp(:));
end
end
Output=uint8(Output);
figure, imshow(Output);

Dyuman Joshi
Dyuman Joshi on 22 Aug 2023
for loops need to be completed with "end". You initiated 2 for loops, but you only closed one.
for i=1:size(I,1)-M
for j=1:size(I,2)-N
% v
Temp=I(i:i+M,j:j+M).*Kernel;% Multiply kernel with original image
Output(i,j)=sum(Temp,'all');
end
%Missing end
end
There might be a typo in the index, as I have highlighted above, you might want to use -
j:j+N

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!