Hi every one, I have a matrix A=1×180. All values of matrix A are either zeros or negative numbers. I need to replace all the zeros by NaN, noted that zeros are also randomly distributed in matrix A. I have tried for loop but do not get the desired result. Any guidance will be appreciated thanks.

댓글 수: 1

拓郎 下山
拓郎 下山 2021년 5월 3일
I have the same problem.
I change 0 value to NaN value in nifti file of int16.
I try "V(V==0) = NaN;"
But, it doesn't work. Could you give me the answer?
Thank you for reading.

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

 채택된 답변

njj1
njj1 2018년 4월 19일

11 개 추천

Try this:

A(A==0) = NaN;

댓글 수: 4

Safi ullah
Safi ullah 2018년 4월 19일
@ njj1, thanks it works well.
Ambati Sathvik
Ambati Sathvik 2020년 5월 22일
Thank you
laith awwad
laith awwad 2021년 4월 21일
HOW TO NAME THE VARIABLE BECAUSE IF I RIGHT FOR EXAMPLE e = A(A==0) = NaN; GIVES ME AN ERROR
If you want to keep the original array around, make a copy of it then replace the values in that copy.
A = randperm(10)
A = 1×10
9 5 7 3 8 10 2 1 4 6
B = A;
B(B > 7) = NaN
B = 1×10
NaN 5 7 3 NaN NaN 2 1 4 6
[A; B] % Use both the original vector (A) and the modified one (B)
ans = 2×10
9 5 7 3 8 10 2 1 4 6 NaN 5 7 3 NaN NaN 2 1 4 6

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 NaNs에 대해 자세히 알아보기

태그

질문:

2018년 4월 19일

댓글:

2021년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by