필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
cfjunior
cfjunior 2013년 10월 24일
댓글: cfjunior 2013년 10월 24일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 24일
편집: Azzi Abdelmalek 2013년 10월 24일
Ok, then just run the second code
idx=isnan(A) | A==0
A(~idx)=1

댓글을 달려면 로그인하십시오.

카테고리

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