How to ignore NaN on functions on vectors

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)

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);

Richiesto:

il 25 Apr 2018

Risposto:

il 25 Apr 2018

Community Treasure Hunt

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

Start Hunting!

Translated by