Hi,
I want to populate a matrix with rows in the form of
0,-1,0,1,-2,-1,0,1,2,-3,-2,-1,0,1,2,30,-1,0,1,-2,-1,0,1,2,-3,-2,-1,0,1,2,30,-1,0,1,-2,-1,0,1,2,-3,-2,-1,0,1,2,3
… ie -x:x for multiple x values. After this, I will call a function on the whole matrix to convert these numbers to something else. eg takesquare(Matrix) will give the elementwise squares of 0,-1,0,1,…
1. How to concatenate -x:x for x=0,1,2,3,..n without a loop? With a loop, solution is trivial and super slow.
2. How can I call the takesquare with additional parameters? So the idea is adding different values to each row, ie takesquare(Matrix, [column vector=2,0,7,1,5,6..]). I know bsxfun can be used, but since the operations should be elementwise, I'll need to repmat the columnvector to all entries then. Is there a better/less memory occupying way?
Thanks!
Best Answer