MATLAB Answers

Replacing NaN with last real value

1 view (last 30 days)
Hi folks, I have hundreds of excel files in .csv format that I have to "clean" getting rid of all teh NaN values and replacin them by the last value.
I have tryied using the repnan function but somethinf seems wrong.
Here is what i did
xlsread ECUSIMTEST0000-000-01.csv
for k=1:size(ans,2)
ans(:,k) = repnan(ans(:,k),"previous")
end
Where ans is the double imported from excel. I am a beginner in matlab so no step is trivial to me.
Thanks !!!

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 15 Jan 2020
If you have R2016b or later releases, use the fillmissing function.
I am not certain what you want to do, so see the method and EndValues documentation sections to fill the NaN values with the values you want. The 'previous', 'next', or 'nearest' methods would llikely be appropriate.

  3 Comments

Diego Dranuta
Diego Dranuta on 15 Jan 2020
Thank you! This worked out
Star Strider
Star Strider on 15 Jan 2020
As always, my pleasure!
Asliddin Komilov
Asliddin Komilov on 17 Jan 2020
I have set of 25 variables (matrices), can I have repliced all zero value to NAN in all of the at once, without doing it for each of them separately?
thanks

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags