Filling in 8x8 matrix with formula
31 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to create a 8x8 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:
- I create a empty matrix A using A = zeros(8,8)
- I create variables p(i) using (pi/16)+(i-1)*(pi/8)
- 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
0 commentaires
Réponse acceptée
KSSV
le 15 Oct 2020
Modifié(e) : KSSV
le 15 Oct 2020
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?
2 commentaires
KSSV
le 16 Oct 2020
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
See that as you wanted, the p is changing the value...it follows as you said.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Assembly dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!