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

1 次查看(过去 30 天)
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!

采纳的回答

Geoff Hayes
Geoff Hayes 2014-9-2
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!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by