MATLAB: For command in function

forfunctionMATLAB

I have a function attached and would like it to automatically run it with x = 2:4 & y = 2:4, that is, the function to run 8 times & have 8 outputs, with inputs
x =2, y = 2
x = 2, y = 3
x = 2, y = 4
x = 3, y = 2
Should I write a 'for' command with the function? It does not seem to work the best this way.

Best Answer

You can use pdist2()
[X,Y] = meshgrid(2:4);
x = X(:);
y = Y(:);
D = pdist2(rowsncolumns,[x y]);
% D(:,1) - first column of D - distance from (rowscolumns) to (x1,y1) point
Indices you want: D == 0
Size of D: 621 x 9