Problem with for loop
4 views (last 30 days)
Show older comments
for i = 1:19
P(i) = [2.8*10^-4:0.1*10^-4:4.2*10^-4]
I cannot figure out how to fix my loop
3 Comments
dpb
on 26 Feb 2014
From what you're showing, you don't need (or want) a loop at all.
doc colon
and read the "Getting Started" section in help on manipulating arrays in Matlab to begin to get the picture.
per isakson
on 26 Feb 2014
P = [2.8e-4:1e-5:4.2e-4];
and
P = [2.8*10^-4:0.1*10^-4:4.2*10^-4];
return identical results.
Accepted Answer
Rick Rosson
on 26 Feb 2014
Edited: Rick Rosson
on 26 Feb 2014
No need for a for loop, no need for square brackets. Also, might as well pull common scale factor out using distributive property:
P = (2.8:0.1:4.2)*1e-4;
More Answers (0)
See Also
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!