Return non-rounded value when assigning variable to index of array

3 ビュー (過去 30 日間)
Ian Bunker
Ian Bunker 2021 年 7 月 28 日
コメント済み: TADA 2021 年 7 月 28 日
Hi,
I currently have a 1 column array with values inside of it, when i run the following command:
timeZero = Y(timeZero);
timeZero is presently storing an index location in the array ideally when this happens I expect timeZero to be assigned to Y at that index value, which in this case is 2.801396127049.
But instead when I call the variable in the command window it returns the value 2.8014. In my application this value needs to retain its decimal places even during assignment. Is there a way to fix this, or change how I approach this issue?
  1 件のコメント
TADA
TADA 2021 年 7 月 28 日
are you sure this value is rounded and not just displayed as a rounded value?
you can change the display precision using
format long

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

回答 (1 件)

Rik
Rik 2021 年 7 月 28 日
You're confusing the data itself with how it is displayed. It is probably a double, meaning the value you attempted to assign was rounded (if necessary) to the nearest value it can encode.
If you need arbitrary (decimal) precision you might want to look into vpa.
I expect the double datatype is already providing you the precision you need.

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by