How to ignore NaN on functions on vectors

40 views (last 30 days)
Jack Bratton
Jack Bratton on 25 Apr 2018
Answered: Image Analyst on 25 Apr 2018
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?

Answers (1)

Image Analyst
Image Analyst on 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);

Categories

Find more on Financial Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!