Constructing it as a vector is possible in theory.
The value range -N to +N is in the (N+1)'th group and is a vector of length (2*N+1). The total length of the vector to the end of the -N:+N group can be found to be (N+1)^2 . Therefore for any given position, M, floor(sqrt(M-1)-1) tells you how many complete N have been gone through, and M minus that gives you the relative position in progress:
Nb = floor(sqrt(M-1)-1);
value_at_M = M - (Nb+1).^2 - 1 + -(Nb+1);
For any given final N, Nf, you can run that vectorized:
M = 1 : (Nf+1).^2;
Nb = floor(sqrt(M-1)-1);
value_at_M = M - (Nb+1).^2 - 1 + -(Nb+1);
"2. How can I call the takesquare with additional parameters? So the idea is adding different values to each row"
You only have one row.
Best Answer