フィルターのクリア

fill missing value in array

4 ビュー (過去 30 日間)
michael
michael 2023 年 7 月 4 日
回答済み: KSSV 2023 年 7 月 4 日
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 Center および File ExchangePreprocessing Data についてさらに検索

タグ

製品


リリース

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by