I have matlab 2013b and all of a sudden the following code for median with omitnan does not work. Can anyone help troubleshoot?

4 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

Star Strider
Star Strider il 25 Mag 2017
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.

Fangjun Jiang
Fangjun Jiang il 26 Mag 2017
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

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by