fill missing value in array

7 次查看(过去 30 天)
Hi,
(unfortunatly, I have old matlab, where timeseries is not existing).
I have an array with data data_array, from which I have selected indeces K which I'd like to use.
I need to generate a new array dest_array , which will be with same length as the original one and populate values to it so that:
If I have selected index k (from K), the value dest_array[k]=data_array[k].
For all the missing enteries, I need to fill with values from previous known one.
What is the best way to do it?

采纳的回答

KSSV
KSSV 2023-7-4
x = 1:100 ;
y = rand(size(x)) ;
% Introduce NaN's randomly
idx = randperm(100,20) ;
y0 = y ;
y(idx) = NaN ;
% Use interp1
yi = interp1(x(~isnan(y)),y(~isnan(y)),idx) ;
% compare
plot(y0(idx),'r')
hold on
plot(yi,'b')
legend('Original','filled')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Preprocessing Data 的更多信息

标签

产品


版本

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by