How to ignore NaN on functions on vectors
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (1)
Image Analyst
le 25 Avr 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);
0 commentaires
Voir également
Catégories
En savoir plus sur Financial Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!