How to ignore NaN on functions on vectors
Mostra commenti meno recenti
I am trying to run a variance ratio test on a vector of stock prices. Some of the prices are missing, and NaN is in those cells. How do I tell matlab to only perform the calculation on cells with data in them?
Risposte (1)
Image Analyst
il 25 Apr 2018
From the R2018a help:
V = var(_,nanflag) specifies whether to include or omit NaN values from the calculation for any of the previous syntaxes. For example, var(A,'includenan') includes all NaN values in A while var(A,'omitnan') ignores them.
If you don't have a recent version of MATLAB, then you'll have to extract non-nan values, like
dataNoNans = data(~isnan(data));
v = var(dataNoNans);
Categorie
Scopri di più su Hypothesis Tests in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!