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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by