I have matlab 2013b and all of a sudden the following code for median with omitnan does not work. Can anyone help troubleshoot?
4 次查看(过去 30 天)
显示 更早的评论
A = [1.77 -0.005 3.98 -2.95 NaN 0.34 NaN 0.19]; M = median(A,'omitnan')
M =
1.7700 -0.0050 3.9800 -2.9500 NaN 0.3400 NaN 0.1900
0 个评论
回答(2 个)
Star Strider
2017-5-25
Use ‘logical indexing’ and the isnan function (as ~isnan):
A = [1.77 -0.005 3.98 -2.95 NaN 0.34 NaN 0.19];
M_omitnan = median(A, 'omitnan')
M_notisnan = median(A(~isnan(A)))
M_omitnan =
0.265
M_notisnan =
0.265
That it is ‘suddenly not working’ means that you could be ‘overshadowing’ it with a variable or usdr function named ‘median’. To determine that, run this line from your Command Window (or a script):
which median -all
You should only get returns on the ‘C:\Program Files\MATLAB\R2013b\toolbox\’ path. Anything else will reveal where the problem is.
0 个评论
Fangjun Jiang
2017-5-26
You must be mistaken about the MATLAB version. The "nanflag" option for the median() function is only available for R2015a and later. See the document link below. Change the hyper link to R2015a to see the difference.
https://www.mathworks.com/help/releases/R2014b/matlab/ref/median.html?searchHighlight=median
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!