Hmm, well, finding y is easy enough:

y = ceil(n/4);

(ceiling function rounds the fraction up to the nearest integer).

You can use this method for x, but you'll have 1 special case.

x = mod(n, 4); // n % 4

(Modulus function) but that won't work when n is a multiple of 4, you have to add this special case:

if(x == 0)

x = 4;

So..just to sum up with Matlab code:

function f = coords(n)

y = ceil(n/4);

x = mod(n, 4);

if(x == 0)

x = 4;

end

end

Hope that helps!