# Question with a row matrix (simple)

1 Ansicht (letzte 30 Tage)
Mate 2u am 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.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Wayne King am 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.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by