How to store value of for loop in a array
Afficher commentaires plus anciens
Hello everyone,
I am trying to store value of A in an array. But some how it stops after 3 itrations at z = 0.03.
Why So? If anybody can have a look where I going wrong.
A = zeros(1,31);
aes = 2;
counter= 1;
for z= 0:0.01:0.3
A(1, counter) = 1/(1+((z/aes)^2));
counter = counter+ 1;
end
A;
Thanks in Advance
Réponse acceptée
Plus de réponses (2)
David Hill
le 14 Oct 2020
A = zeros(1,31);
aes = 2;
counter= 1;
for z= 0:0.001:0.03%I believe you want the interval to be .001 (otherwise loop only runs for 4 times)
A(1, counter) = 1/(1+((z/aes)^2));
counter = counter+ 1;
end
madhan ravi
le 14 Oct 2020
for z = linspace(0, 0.03, 31)
By the way you don’t need a Loop it’s simply:
A = 1 ./ (1 + ((z / aes) .^ 2))
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!