fill missing value in array

7 vues (au cours des 30 derniers jours)
michael
michael le 4 Juil 2023
Réponse apportée : KSSV le 4 Juil 2023
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?

Réponse acceptée

KSSV
KSSV le 4 Juil 2023
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')

Plus de réponses (0)

Catégories

En savoir plus sur Preprocessing Data dans Help Center et File Exchange

Produits


Version

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by