Filter löschen
Filter löschen

Ho do i insert 0 to a data based on a condition

1 Ansicht (letzte 30 Tage)
Shambhavi Adhikari
Shambhavi Adhikari am 29 Jan. 2020
Beantwortet: Guillaume am 29 Jan. 2020
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);

Antworten (1)

Guillaume
Guillaume am 29 Jan. 2020
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

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by