how to do mean of a column with a loop and excluding nans?
4 次查看(过去 30 天)
显示 更早的评论
so i have this large file that is contains nans randomly, its a 1140 X 1 matrix i want to do a for loop that excludes all the nans and do the mean of that can someone explain me how to do this?
采纳的回答
Birdman
2018-3-16
编辑:Birdman
2018-3-16
You do not need a for loop. Matlab's mean function has an option of omitnan. You can use it as follows:
res=mean(a,'omitnan')
4 个评论
Birdman
2018-3-16
res is used to sum up the variables that are not NaN, that is it. You need a variable to sum up the variables that are not NaN in a for loop, therefore you need it and cnt simply counts how many times that if statement is entered.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!