Fractional steps in for loops

9 views (last 30 days)
IDN
IDN on 29 Dec 2021
Commented: IDN on 29 Dec 2021
Hello! This is the first time i am running fractional steps in for loop and i am not sure wheter this is just comepletely wrong or if this is the way it works.
yHH = 1:0.1:3;
for yH = 1:length(yHH)
Function(yH)
end
i get the following output
1
4
3
5
1
3
4
10
So what I was expecting was 1.1,1.2,1.3, etc....but I got the above numbers. Are those index numbers like for example below
1 = 1
2 = 1.1 % index 2 equates to the the second step within then range?
3 = 1.2
4 = 1.3
......
10 = 1.9
Appreciate any help! Thanks!

Accepted Answer

Voss
Voss on 29 Dec 2021
yHH = 1:0.1:3;
for yH = 1:length(yHH)
display(yH);
end
yH = 1
yH = 2
yH = 3
yH = 4
yH = 5
yH = 6
yH = 7
yH = 8
yH = 9
yH = 10
yH = 11
yH = 12
yH = 13
yH = 14
yH = 15
yH = 16
yH = 17
yH = 18
yH = 19
yH = 20
yH = 21
compare to:
yHH = 1:0.1:3;
for yH = 1:length(yHH)
display(yHH(yH));
end
1 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 2.8000 2.9000 3
  1 Comment
IDN
IDN on 29 Dec 2021
Perfect, thanks so much !

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!