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

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 件のコメント

OCDER
OCDER 2018 年 10 月 10 日
How are you generating A =, B = , C = ?
If these are in one matrix or cell array, then you could use fillmissing
or a combination of isnan logical index and replacement.
If you have a lot of unique variables, then you're out of luck and need to rework your code to avoid creating so many variable names.
harshpurohit11
harshpurohit11 2018 年 10 月 10 日
Thanks a lot for the suggestion but I was not able to find the function fillmissing in matlab 2014a
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 日

0 投票

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
>>

カテゴリ

ヘルプ センター および File ExchangeInterpolation of 2-D Selections in 3-D Grids についてさらに検索

製品

リリース

R2014a

質問済み:

2018 年 10 月 10 日

コメント済み:

2018 年 10 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by