1. ## matrices / coordinates

Hi all

Im all new to this forum. I have a website project where I have run into a math problem.

My problem is that i get a specifik number (n), which creates a number of boxes in a matrix. The coordinates of each box should be calculated using a formula, but I cant solve it myself.

The following should be true:

n=1, x=1, y=1
n=2, x=2, y=1
n=3, x=3, y=1
n=4, x=4, y=1
n=5, x=1, y=2
n=6, x=2, y=2
n=7, x=3, y=2
n=8, x=4, y=2
n=9, x=1, y=3

And so forth

I need a function which says something:

If n=something, x=something and y=something.

The matrix is a 4xZ matrix, where Z depends on the number of entries.
With 1-4 entries, Z=1, with 5-8 entries, Z=2 etc.

I can solve it for n=1-4, but then it gets too complicated for me.

I hope anyone can help or point me in the right direction.

Thanks a lot :-)

2. 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!

3. HI

Thanks a lot. It worked for me :-)