Vectorisation: Colon operator with floating point increment error

5 ビュー (過去 30 日間)
Manu M
Manu M 2019 年 4 月 7 日
回答済み: Walter Roberson 2019 年 4 月 7 日
Hi,
For y=400:1.6:1200; Expected output is =400, 401.6,...1198.4,1200.
But Matlab gives output in the form: 1.0e+03 *Columns 1 through 11 0.4000 0.4016 0.4032 ...1.200.
Can you advise how to get the expected output. If it has already been addressed, kindly share the link to look through.
Thanks!

採用された回答

Manu M
Manu M 2019 年 4 月 7 日
y=400:1.6:1200;
z=round(y);
  1 件のコメント
madhan ravi
madhan ravi 2019 年 4 月 7 日
編集済み: madhan ravi 2019 年 4 月 7 日
What?? did you inspect the values first?? You ask in the question that you want the second element to be 401.6 whereas after round you get 402, are you aware of it?? If latter was the desired result then wouldn't be simpler to use:
y = 400:2:1200 % ??

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 4 月 7 日
Give the command
format long g
and then display the data again.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by