The sample points must be finite.

111 vues (au cours des 30 derniers jours)
jie hu
jie hu le 20 Juin 2023
Commenté : jie hu le 21 Juin 2023
I like to interpolate a sample data on a new timeline by useing interp1, saying "The sample points must be finite."
data_origin=readtable('data_origin.csv');
time=data_origin.Var1;
elev=data_origin.Var2;
%% note the start date in raw data is {'05-Jan-2020 17:40:00'}
%% end date in raw data is {'09-Nov-2020 16:20:00'}
timeline = ( datetime(2020,1,5) + minutes((1060:25:24*60*310-5*92)) ).' ;
%% interpolate schism result to 'obs_tide_time'
interp_elev = interp1(datenum(time(:)),double(elev(:)),datenum(timeline(:)),'linear','extrap');

Réponse acceptée

Askic V
Askic V le 20 Juin 2023
Most likely, you're getting the error because you have missing entries in the data.
websave("filename.csv","https://www.mathworks.com/matlabcentral/answers/uploaded_files/1415214/data_origin.csv");
data_origin = readtable("filename.csv");
timeData = data_origin.Var1;
values = data_origin.Var2;
% Convert datetime to numerical values
timestamps = datenum(timeData);
% Remove NaN or Inf values from the arrays
validIndices = isfinite(timestamps);
timestamps = timestamps(validIndices);
values = values(validIndices);
data_origin(188:190,:)
ans = 3×2 table
Var1 Var2 ____________________ ____ 08-Jan-2020 23:35:00 0.44 NaT 0.47 09-Jan-2020 00:25:00 0.5
% Is there missing entries in the data:
missing_entries = any(isnat(data_origin.Var1) | isnan(data_origin.Var2));
if missing_entries
% remove mising entries
data_origin = rmmissing(data_origin);
end
% Define new extrapolation range
extrap_start = datenum('05-Jan-2020 17:10:00');
extrap_end = datenum('10-Nov-2020 00:20:00');
% Convert new timestamps to numerical values
extrap_timestamps = linspace(extrap_start, extrap_end, numel(values));
% Perform linear extrapolation using interp1
extrap_values = interp1(timestamps, values, extrap_timestamps, 'linear', 'extrap');
% Convert numerical timestamps back to datetime format
extrap_datetime = datetime(extrap_timestamps, 'ConvertFrom', 'datenum');
plot(extrap_datetime, extrap_values)
  1 commentaire
jie hu
jie hu le 21 Juin 2023
Really appreciated, Askic!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by