I have an array of cells, each of which contains a sequence of values as a row vector. The sequences contain some missing values represented by NaN .
I would like to replace all NaN using some kind of interpolation method, how can I do this in MATLAB? I am also open to other suggestions on how to deal with these missing values.
Consider this sample data to illustrate the problem:
seq = {randn(1,10); randn(1,7); randn(1,8)}; for i=1:numel(seq) %# simulate some missing values ind = rand( size(seq{i}) ) < 0.2; seq{i}(ind) = nan; end
The resulting sequence:
seq{1} ans = -0.50782 -0.32058 NaN -3.0292 -0.45701 1.2424 NaN 0.93373 NaN -0.029006 seq{2} ans = 0.18245 -1.5651 -0.084539 1.6039 0.098348 0.041374 -0.73417 seq{3} ans = NaN NaN 0.42639 -0.37281 -0.23645 2.0237 -2.2584 2.2294
Edit:
Based on the answers, I think there was confusion: it’s obvious that I don’t work with random data, the above code is just an example of how the data is structured.
Actual data is some form of processed signal. The problem is that during the analysis, my solution would fail if the sequences contain missing values, therefore, the need for filtering / interpolation (I already thought that I use the average of each sequence to fill in the gaps, but I hope for something more powerful)
matlab nan interpolation missing-data
Dave
source share