Remove non-finite values while decimating

4 visualizaciones (últimos 30 días)
Taylor Azizeh
Taylor Azizeh el 31 de Oct. de 2023
Comentada: Taylor Azizeh el 9 de Nov. de 2023
I was able to decimate 8 other identical (or so I thought) files, but this one hit an error. Code and error below:
%% Set path
cd 'C:\folder'
%% Load data
data = readtable('data.csv');
%% Decimate and then convert to table format
data50_X = decimate(data{:,4},2);
Error using filtfilt
Expected input to be finite.
Error in filtfilt>efiltfilt (line 123)
validateattributes(x,{'double','single'},{'finite','nonempty'},'filtfilt');
Error in filtfilt (line 102)
y = efiltfilt(b,a,x);
Error in decimate (line 157)
odata = filtfilt(b,a,idata);

Respuesta aceptada

Image Analyst
Image Analyst el 1 de Nov. de 2023
Try this:
data = readtable('data.csv');
goodRows = isfinite(data{:, 4});
data = data(goodRows, :); % Extract only the good/finite values rows.
  9 comentarios
Image Analyst
Image Analyst el 9 de Nov. de 2023
Sorry, you need another argument for all to make it apply across columns. Try this:
%% Load in your data (this may take a while, depdending on the size of the file)
data = readtable('small_data.csv');
%% Decimate and then convert to table format
goodRows = all(isfinite(data{:, 4:6}), 2);
data = data(goodRows, :) % Extract only the good/finite values rows
data = 1000×18 table
TagID Date Time X Y Z Activity Depth Temp___C_ location_lat location_lon height_msl ground_speed satellites hdop signal_strength SensorRaw Metadata _______________________ ___________ ____________ ______ ______ _ ______________ _____ _________ ____________ ____________ __________ ____________ __________ ____ _______________ _________ ________ {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.000 -0.063 -0.063 1 {'Active/Dry'} 0 18.6 NaN NaN NaN NaN NaN NaN NaN 997 NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.010 -0.063 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.020 -0.063 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.030 -0.063 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.040 -0.003 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.050 -0.059 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.060 -0.004 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.070 0 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.080 -0.058 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.090 -0.063 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.100 -0.063 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.110 -0.063 -0.007 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.120 -0.008 -0.055 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.130 -0.054 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.140 -0.063 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'EP19_PEN19_EP9_B_S1'} 30-Oct-2019 19:49:07.150 -0.063 -0.063 1 {0×0 char } NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Taylor Azizeh
Taylor Azizeh el 9 de Nov. de 2023
Fixed!! Thank you so much for your help, you're a lifesaver.

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 31 de Oct. de 2023
Editada: Matt J el 31 de Oct. de 2023
Likely, there are NaNs in your data that you have to remove.
find(~isfinite(data{:,4}))
  5 comentarios
Matt J
Matt J el 1 de Nov. de 2023
find(~isfinite(data{:,4})) gives the locations of the bad data. You can go there and see what those values are, and either remove them or replace them with something else.
Taylor Azizeh
Taylor Azizeh el 1 de Nov. de 2023
Ohhhh gotcha. Thank you so much!

Iniciar sesión para comentar.

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by