Azzera filtri
Azzera filtri

Replace values like (-999) in matrix to zero with one statement?!

1 visualizzazione (ultimi 30 giorni)
I am looking for replacing values (-999) in a matrix (m*3) to zero. I can do that using for/While loop but my program is going to be delayed to execute.
Anyone experience change a values to zero?
Thanks in advance!

Risposta accettata

Geoff Hayes
Geoff Hayes il 2 Set 2014
Mohammed - try something like the following. If mtx is your matrix
% create a 5x5 matrix
mtx = [-999 1 2 3 4;
5 -999 6 7 8;
9 10 -999 11 12;
13 14 15 -999 16;
17 18 19 20 -999];
% set all elements that are -999 to zero
mtx(mtx==-999) = 0;
This works only if the value you wish to replace is an integer.
Try the above and see what happens!

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by