samedi 18 novembre 2017

Replacing NaN with random variables that keep the standard deviation in MATLAB

I have a matrix A as a row vector containing some missing values NaN. Let's assume it looks like the following:

A = [2; NaN; 0.3; NaN; -0.8; NaN; 1; -0.5; NaN; 0.2];

The series has a mean = nanmean(A, 1) of 0.37 and a std = nanstd(A, 1) of 0.93.

Question 1) How can I replace the missing values NaN in A with random variables (positive and negative values)?

Question 2) How can I replace the missing values NaN in A with random variables that are not smaller than -1 nor are they greater than 1?

Question 3) How can I replace the missing values NaN in A with random variables (positive and negative), yet keep the std the same?

Question 4) How can I replace the missing values NaN in A with random variables (positive and negative), yet keep the std the same with random that are not smaller than -1 nor are they greater than 1?




Aucun commentaire:

Enregistrer un commentaire