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 件のコメント

Stephen23
Stephen23 2022 年 4 月 24 日
編集済み: Stephen23 2022 年 4 月 24 日
"why I have error in the command linspace"

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

回答 (1 件)

Image Analyst
Image Analyst 2022 年 4 月 23 日

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 = 1×100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
x = linspace(1, 100, 100) % Start at 1, not 0
x = 1×100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2022 年 4 月 23 日

編集済み:

2022 年 4 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by