MATLAB: Convolution Mask

convolution

To start, I have 3 matrices:
m1= [3 x 3]
m2= [5 x 5]
m2= [7 x7]
I have three loops that are used depending on the size of the matrix. I want to use an "if" command to decifer the size of matrix so the appropriate loop is used.
Here is an example of the 3 x 3 case.
function [matrix]= three_by_three(x,y,I)
if m1 =
matrix= [I(x-1, y-1), I(x-1, y), I(x-1, y+1); I(x, y-1), I(x,y), I(x, y+1); I(x+1, y-1), I(x+1, y), I(x+1, y+1)];
end

Best Answer

Something like this?
sz = size(matrix);
if isequal(sz, [3 3])
% first for loop, function call or whatever
elseif isequal(sz, [5 5])
% second
elseif isequal(sz, [7 7])
% third
else
error('myfunction:badsize', 'Unexpected matrix size');
end
You could also use a switch statement.