Ho do i insert 0 to a data based on a condition
2 ビュー (過去 30 日間)
古いコメントを表示
I have a 1 Hz table with timestamps and number. This table has NaNs. When i removed NaNs from the number column. My difference (duration) in time is now 1 seconds, 30 seconds, 50 seconds and so on. I want to insert zeroes to number column where the duration is more than 20 seconds.the zeroes should be equal to the seconds of the duration because eventually it's a 1 second data. I tried using interpolation. It's not helping. Can anyone suggest something here?
I used pchip because we can use pchip to insert any number.
New_number = zeros(size(data,1), 1);
complete_timestamps = data{:,1};
% Collapse to remove all NaNs values
real_index = find(~isnan(data.number));
timestamps_data_points = complete_timestamps(real_index);
number_data_points=data.number(real_index);
for iii=2:size(timestamps_data_points)-1
if dt(iii)>= seconds(15)
New_number(:,1)= interp1(timestamps_data_points,number_data_points,complete_timestamps,'pchip',0);
else
New_number(:,1)=NaN;
end
end
New_number(:,1);
0 件のコメント
回答 (1 件)
Guillaume
2020 年 1 月 29 日
Rather than removing the NaNs and trying to fill afterward wouldn't you be better served by replacing the NaNs using interpolation for example? For this, you have fillmissing:
filleddata = fillmissing(data, 'pchip', 'DataVariables', 'number'); %you may not need to specify the DataVariables if all your table contain is timestamp and number
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Preprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!