フィルターのクリア

The sample points must be finite.

91 ビュー (過去 30 日間)
jie hu
jie hu 2023 年 6 月 20 日
コメント済み: jie hu 2023 年 6 月 21 日
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');

採用された回答

Askic V
Askic V 2023 年 6 月 20 日
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 件のコメント
jie hu
jie hu 2023 年 6 月 21 日
Really appreciated, Askic!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by