The sample points must be finite.
88 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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');
0 Commenti
Risposta accettata
Askic V
il 20 Giu 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,:)
% 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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Time Series Objects in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!