covert NaN to zeros

11 ビュー (過去 30 日間)
John fredson
John fredson 2022 年 5 月 11 日
コメント済み: Walter Roberson 2022 年 5 月 15 日
“These will contain the value ‘NaN’ when imported. You should replace these with a value of zero.“ For a given set of data, it contains NaN in some where, how to pick then up and assign a zero to then as stated as the statement?
  1 件のコメント
dpb
dpb 2022 年 5 月 11 日
x(isnan(x))=0;
the most basic of logical indexing.

サインインしてコメントする。

回答 (3 件)

John fredson
John fredson 2022 年 5 月 12 日
Check for incorrect argument data type or missing argument in
call to function 'isnan'.
Error in Q1a (line 16)
x(isnan(X))=0 ;
this error occurs
  2 件のコメント
Steven Lord
Steven Lord 2022 年 5 月 12 日
What type of variable is x? Is it double, like d in the example below? Is it a table array, like t? Is it a cell array like c? Or is it some other type?
d = 1:10;
t = array2table(magic(4));
c = {'apple', 'banana'};
whos
Name Size Bytes Class Attributes c 1x2 230 cell cmdout 1x33 66 char d 1x10 80 double t 4x4 1759 table
If it's either double or table, I'd use fillmissing instead of assignment with isnan. isnan is not defined for table arrays but fillmissing can fill missing data inside a table.
d(5) = NaN
d = 1×10
1 2 3 4 NaN 6 7 8 9 10
d2 = fillmissing(d, 'Constant', 0)
d2 = 1×10
1 2 3 4 0 6 7 8 9 10
t{2, 3} = NaN
t = 4×4 table
Var1 Var2 Var3 Var4 ____ ____ ____ ____ 16 2 3 13 5 11 NaN 8 9 7 6 12 4 14 15 1
t2 = fillmissing(t, 'Constant', 0)
t2 = 4×4 table
Var1 Var2 Var3 Var4 ____ ____ ____ ____ 16 2 3 13 5 11 0 8 9 7 6 12 4 14 15 1
John fredson
John fredson 2022 年 5 月 15 日
it is textdata

サインインしてコメントする。


John fredson
John fredson 2022 年 5 月 12 日
I have a set of struct data, may I know how can I plot it in the subplot?
  1 件のコメント
Steven Lord
Steven Lord 2022 年 5 月 12 日
This doesn't seem to be related to the original question of how to replace NaN values with 0, so you should ask this as a new question (with more details about how the data is organized in your struct.) Use the Ask link just below the blue "MATLAB Answers" bar at the top of the page.

サインインしてコメントする。


Image Analyst
Image Analyst 2022 年 5 月 15 日
You say you have "text data".
Not sure what you really have, but look at this:
textData = 'abcdef';
textData(3) = nan
textData = 'ab def'
textData(isnan(textData)) = 0
textData = 'ab def'
textData(3)
ans = ' '
textData(3) = '0'
textData = 'ab0def'
Does that do anything like what you want and expect? If not, attach your variable in a .mat file with the paperclip icon after reading this:
  2 件のコメント
John fredson
John fredson 2022 年 5 月 15 日
The question are as follow
Walter Roberson
Walter Roberson 2022 年 5 月 15 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by