covert NaN to zeros

3 views (last 30 days)
John fredson
John fredson on 11 May 2022
Commented: Walter Roberson on 15 May 2022
“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 Comment
dpb
dpb on 11 May 2022
x(isnan(x))=0;
the most basic of logical indexing.

Sign in to comment.

Answers (3)

John fredson
John fredson on 12 May 2022
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 Comments
John fredson
John fredson on 15 May 2022
it is textdata

Sign in to comment.


John fredson
John fredson on 12 May 2022
I have a set of struct data, may I know how can I plot it in the subplot?
  1 Comment
Steven Lord
Steven Lord on 12 May 2022
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.

Sign in to comment.


Image Analyst
Image Analyst on 15 May 2022
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:

Community Treasure Hunt

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

Start Hunting!