fill missing value in array

3 Ansichten (letzte 30 Tage)
michael
michael am 4 Jul. 2023
Beantwortet: KSSV am 4 Jul. 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?

Akzeptierte Antwort

KSSV
KSSV am 4 Jul. 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')

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Produkte


Version

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by