Keep in mind that Matlab starts numbering with 1. Then useful features are
zeros(m,n) % Makes a 2D array with m rows and n columns, filled with zero ones(m,n) % Same thing with one reshape(a , m , n) % Turns an array with m*n elements into am,n square
The latter is useful if you build a linear array, but then want to make a square one out of it. (If you want to count columns instead of rows, reshape(a,n,m)' .
You can also perform an external product of two vectors:
> [1;2;3]*[1 2 3] ans = 1 2 3 2 4 6 3 6 9
In order to actually build an array with the math you are describing, you will probably have to iterate over it on at least one axis with the for loop.
source share