Question with a row matrix (simple)

1 view (last 30 days)
Mate 2u
Mate 2u on 15 Jun 2012
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.

Accepted Answer

Wayne King
Wayne King on 15 Jun 2012
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.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!