How to store value of for loop in a array
Show older comments
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
Accepted Answer
More Answers (2)
David Hill
on 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
on 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))
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!