フィルターのクリア

How to reduce precision of data greator than zero only? (Matlab R2019a)

1 回表示 (過去 30 日間)
taimour sadiq
taimour sadiq 2021 年 3 月 16 日
コメント済み: taimour sadiq 2021 年 3 月 16 日
Hello... Lets suppose i have a data stored in a variable
A = [1.23323 45.24343 0.1 0.001 455.34543 0.0001 ]
i want to shrink pricision of data only greator than zero... i tryed
A(A>0) - str2double(compose('%.2f',A(A>0)))
so the result should be
A = [1.23 45.24 0.1 0.001 455.34 0.0001] %% <<<< Desired Results
but its not woking, it applying %.2f on whole data....and giving >>>
A = [1.23 45.24 0.10 0.00 455.34 0.00]
Kindly Guide. Thanks
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 16 日
so the result should be
No, 0.001 is greater than 0, so it should have its precision reduced.
taimour sadiq
taimour sadiq 2021 年 3 月 16 日
ooops....Yes you r right... my basic mistake ...

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 16 日
format long g
A = [1.23323 -45.24343 0.1 0.001 455.34543 -0.0001 ]
A = 1×6
1.23323 -45.24343 0.1 0.001 455.34543 -0.0001
mask = A>0;
A(mask) = round(A(mask),2);
A
A = 1×6
1.23 -45.24343 0.1 0 455.35 -0.0001
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 16 日
It is possible that what you really want is
format long g
A = [1.23323 -45.24343 0.1 0.001 455.34543 -0.0001 ]
A = 1×6
1.23323 -45.24343 0.1 0.001 455.34543 -0.0001
mask = abs(A)>0.01;
A(mask) = round(A(mask),2);
A
A = 1×6
1.23 -45.24 0.1 0.001 455.35 -0.0001

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by