How to replace elements different than 0 and different than NaN to 1?

1 次查看(过去 30 天)
I have this huge matrix with a lot of elements: (i) equal to zero; (ii) number different than zero; (iii) NaN values ...
I need to replace all the the NUMBERS different than 0 to 1.
How do I do it not replacing the NaN values?

采纳的回答

Mohammad Monfared
Mohammad Monfared 2013-10-24
Let the matrix name, A, so this is done by:
A(xor((A~=0),isnan(A))) = 1 ;

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-10-24
编辑:Azzi Abdelmalek 2013-10-24
A(A~=0)=1
%or maybe you want
idx=isnan(A) | A==0
A(~idx)=1
  3 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by