Fractional steps in for loops

7 ビュー (過去 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
  1 件のコメント
IDN
IDN 2021 年 12 月 29 日
Perfect, thanks so much !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by