フィルターのクリア

Rounding Vector Entries with zeros after the decimal place to integers

1 回表示 (過去 30 日間)
Eli Dim
Eli Dim 2015 年 7 月 7 日
回答済み: Titus Edelhofer 2015 年 7 月 7 日
I have a vector T (attached file) which is an input for a function. Row 44 is a problem for me (112.0000). How can I do a loop which says, if you have an entry in my vector which has only zeros after the decimal place, convert the number to an integer (112). If I do round, ceil etc. on vector T, my function afterwards works, however, the rounding leads to answers which are too far away from reality. Thank you for your help.
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 7 日
What is your problem? Do you just need to display your data the way you asked or what?

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

採用された回答

Titus Edelhofer
Titus Edelhofer 2015 年 7 月 7 日
Hi,
use Azzi's answer if displaying of results is what you after. If you want to eliminate some numerical noise from values that should be integers (but leave the others untouched) do something like
v = [1.0000000001 2.3 3.4];
idx = abs(v-round(v))<1e-6;
v(idx) = round(v(idx));
Now v(1) is exactly one ...
Titus

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 7 日
編集済み: Azzi Abdelmalek 2015 年 7 月 7 日
sprintf('%d\n',T)
or
out=num2str(T)

カテゴリ

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