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

3 views (last 30 days)
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!

Accepted Answer

Geoff Hayes
Geoff Hayes on 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!

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!