why I have error in the command linspace
이전 댓글 표시
I used the command x = linspace(0,100)
I expec to have value that range (1, 2, 3, etc....)
why do I get (0 1.01010101010101 , 2.02020202020202 , 3.03030303030303 , 4.04040404040404)
댓글 수: 1
"why I have error in the command linspace"
Because of this: https://en.wikipedia.org/wiki/Off-by-one_error#Fencepost_error
답변 (1개)
It defaults to 100 elements. So 0 to 100 is 101 integers so of course they will be slightly larger. If you want 1,2,3 you can do one of these two ways
x = 1 : 100
x = linspace(1, 100, 100) % Start at 1, not 0
댓글 수: 1
Walter Roberson
2022년 4월 23일
or linspace(0,100,101)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!