Matlab create matrix without loops

659 Views Asked by At

I'm trying to create a Matrix in Matlab, which is dependent on 2 control variables $i$ and $n$. They are defined like this: $i=1:10$, $n=0:N-1$.

Now I'm trying to define a matrix, where an entry is: $cos((i/5)*pi*n)$. With every line $i$ shall increase and with every column $n$.

How can I perform this without using any loops?

Thank you very much

1

There are 1 best solutions below

1
On BEST ANSWER

There are may ways, but the easiest is to take the outer product of the vectors:

cos(pi/5 * (1:10)' * (0:N-1))

Other possibilities include using meshgrid() and repmat().