How to ignore NaN on functions on vectors
40 views (last 30 days)
Show older comments
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 Comments
Answers (1)
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);
0 Comments
See Also
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!