Error using zeros "Size inputs must be integers"

Hi all,
I have a very bizarre problem with zeros. When typing:
zeros(10*(1-.7),1)
I get the following error:
Error using zeros
Size inputs must be integers.
Although using zeros(10*(.3),1) or zeros(10*(1-.6),1) doesn't cause any problem.

1 件のコメント

Panali Pérez Reyes
Panali Pérez Reyes 2021 年 6 月 14 日
Use the "round ()" function to make sure that the values you enter to the "zeros ()" command are integers.

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

 採用された回答

Adam
Adam 2014 年 9 月 15 日
編集済み: Adam 2014 年 9 月 15 日

4 投票

Floating point maths is not guaranteed to result in exact integer values. Just use the 'round' function if you need to use the result of such maths as an index into an array.
There are others with far greater expertise than me on this issue who may add comments/answers, but 0.7 may not be precisely represented meaning that 1 - 0.7 will not be precisely 0.3 (close enough for us not to care, but not precise enough to count as an integer when multiplied by 10).

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by