How to interpolate/resample an irregular dataset into 1 step spacing?

Hi all!
I am trying to resample my irregular dataset (on age) to regular 1 step intervals. The data was previously resampled from depth to age using tie points, but I have no tie points to the 1 step intervals. I'm trying to interpolate the data 0:1:3000.
I have tried 'resample' and 'interp1' but think I must be doing something wrong as I get outputs not on regular 0:1:3000 steps, or error messages.
interval_resampled = resample(dataset_resample_issue(:,1);, dataset_resample_issue(:,2);, ((0:1:3000).'));
Error using resample
Expected input number 3, Fs, to be a scalar.
Error in resample>validateFs (line 842)
validateattributes(fs, {'numeric'},{'real','finite','scalar', ...
Error in resample>nonUniformResample (line 285)
validateFs(fs);
Error in resample (line 235)
nonUniformResample(isDimValSet,Dim, m, method1, dimIn, xIn, ...
Any advice would be much appreciated! Thank you!
Becky

1 Commento

What do you want to do?
The current ranges for the variables are:
LD = load(websave('dataset_resample_issue','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1205953/dataset_resample_issue.mat'));
dataset = LD.dataset
dataset = 5020×2
10.5908 0.0750 11.2968 0.0858 12.0029 0.0931 12.7089 0.1025 13.4150 0.1097 13.7222 0.1157 14.0295 0.1180 14.3367 0.1190 14.6439 0.1183 14.9512 0.1167
format longg
MinMax = [min(dataset); max(dataset)]
MinMax = 2×2
1.0e+00 * 10.5907898945244 -7.91884 2903.14453867717 0.383486
.

Accedi per commentare.

 Risposta accettata

hello Becky
try this
the second case means you ask interp1 to do extrapolation, as your original x data do not covers the entire 0 to 3000 range
use at your own risks !
load('dataset_resample_issue.mat')
x = dataset(:,1);
y = dataset(:,2);
% remove first NaNs in x array
idx = ~isnan(x);
x = x(idx);
y = y(idx);
%% option 1 : no extrapolation (xi will go from 11 to 2903 by step = 1 )
xi = ceil(x(1)):1:floor(x(end)); % make sure the new x axis correspond to the min / max range of x (after NaN removal)
yi = interp1(x,y,xi,'linear');
figure(1),plot(x,y,'b*',xi,yi,'r-');
legend('input data', 'resampled data');
%% option 2 : with extrapolation (xi will go from 0 to 3000 by step = 1 )
xi = 0:1:3000; % make sure the new x axis correspond to the min / max range of x (after NaN removal)
yi = interp1(x,y,xi,'linear','extrap');
figure(2),plot(x,y,'b*',xi,yi,'r-');
legend('input data', 'resampled data');

2 Commenti

Hi Mathieu!
Option one worked prefectly for what I'm after - thank you very much!
Becky

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Interpolation in Centro assistenza e File Exchange

Prodotti

Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by