nested if-else inside nested if-else
显示 更早的评论
In the following program it showed error in line 22.If elseif statement can't be used in this way,please suggest alternative way.
%code
function output = blur(img,w)
img(:) = double(img(:))+1;
[row col] = size(img);
output = zeros(row, col);
for i=1:row
for j=1:col
if (i-w)<1
if (j-w)<1
A = img([1:i+w,1:j+w]);
k = mean( img ,'all');
output(i,j) = k;
elseif (j+w)>col
A = img([1:i+w,j-w:col]);
k = mean( img ,'all');
output(i,j) = k;
else
A = img([1:i+w,j-w:j+w]);
k = mean( img ,'all');
output(i,j) = k;
end
elseif (i+w)>row
if (j-w)<1
A = img([i-w:row,1:j+w]);
k = mean( img ,'all');
output(i,j) = k;
elseif (j+w)>col
A = img([i-w:row,j-w:col]);
k = mean( img ,'all');
output(i,j) = k;
else
A = img([i-w:row,j-w:j+w]);
k = mean( img ,'all');
output(i,j) = k;
end
else
if (j-w)<1
A = img([i-w:i+w,1:j+w]);
k = mean( img ,'all');
output(i,j) = k;
elseif (j+w)>col
A = img([i-w:i+w,j-w:col]);
k = mean( img ,'all');
output(i,j) = k;
else
output(i,j) = mean(img(i-w:i+w,j-w:j+w));
end
end
end
end
output(:) = uint8(round(output(:)-1));
Error: File: blur.m Line: 22 Column: 5
Illegal use of reserved keyword "elseif".
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Software Development Tools 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
