フィルターのクリア

Question with a row matrix (simple)

2 ビュー (過去 30 日間)
Mate 2u
Mate 2u 2012 年 6 月 15 日
Hi there, I have a matrix of size 500000 x 1. I want to minus 0.00006 from each element which is not zero. If there is a zero then it would not minus from 0.

採用された回答

Wayne King
Wayne King 2012 年 6 月 15 日
You probably want to use some tolerance from zero
x = randn(500000,1);
indices = find(abs(x-0)<eps);
x(indices) = x(indices) - 0.00006;
The tolerance is assuming that you have a vector of floating point numbers here. I've used eps with no argument, it may be better here to use eps(0), which is a smaller number, than eps, but it's hard to say not knowing your application. It may be sufficient for you to just use some small number bigger than eps like 1e-6 for example.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by