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

3 ビュー (過去 30 日間)
Mohammed
Mohammed 2014 年 9 月 2 日
コメント済み: Mohammed 2014 年 9 月 3 日
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!
  1 件のコメント
Mohammed
Mohammed 2014 年 9 月 3 日
God! I even knew how to use this. Forgot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by