Fractional steps in for loops

3 次查看(过去 30 天)
IDN
IDN 2021-12-29
评论: IDN 2021-12-29
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!

采纳的回答

Voss
Voss 2021-12-29
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by