필터 지우기
필터 지우기

How to remove/replace NaN from multiple variables in workspace?

조회 수: 7 (최근 30일)
harshpurohit11
harshpurohit11 2018년 10월 10일
댓글: Stephen23 2018년 10월 11일
I have a number of variables in workspace: A = [NaN; NaN; NaN; 1; 2; 3..]; B = [NaN; NaN; NaN; NaN; 4; 27; 31..]; C = [NaN; NaN; 10; 21; 34..]; et cetra and I need to replace NaNs from double with a 0.
  댓글 수: 4
madhan ravi
madhan ravi 2018년 10월 11일
See my answer below.
Stephen23
Stephen23 2018년 10월 11일
"I have a number of variables in workspace: A... B... C ... et cetra and I need to replace NaNs from double with a 0."
Then you should redesign your code. Magically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know more:
<https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval

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

답변 (1개)

madhan ravi
madhan ravi 2018년 10월 10일
편집: madhan ravi 2018년 10월 10일
An example:
>> A = [NaN; NaN; NaN; 1; 2; 3]
A(isnan(A))=0
A =
NaN
NaN
NaN
1
2
3
A =
0
0
0
1
2
3
>>

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by