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

1 Ansicht (letzte 30 Tage)
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!

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 2 Sep. 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!

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB 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