MATLAB: Filling in 8×8 matrix with formula

for loopMATLABmatrix

I want to create a 8×8 matrix and fill in the values using a formula. This is the workflow I have in mind is to create some nested for loop that does this:
  1. I create a empty matrix A using A = zeros(8,8)
  2. I create variables p(i) using (pi/16)+(i-1)*(pi/8)
  3. I create a(i,j) = cos((j-1)*p(i)) to fill in matrix
This is what I have tried:
A = zeros(8,8)
for i = 1:8
p(i) = (pi/16)+(i-1)*(pi/8)
for i = 1:8
for j = 1:8
A(i,j) = cos((j-1)*p(i))
Thank you

Best Answer

A = zeros(8,8)
for i = 1:8
p = (pi/16)+(i-1)*(pi/8)
for j = 1:8
A(i,j) = cos((j-1)*p)
end
end
As the input values of cos are very small...all of them are 1....check your formula is it correct?
Related Question