Interpolating one variable to another with duplicate data points using interp1 - Error: Sample points must be unique.
Afficher commentaires plus anciens
I am trying to interpolate data based on another variable, to 360 data points long. So for every increase of 1 degree in the pr_transpose variable, we can see what the sr_transpose variable is for 360 degrees. I have written the following code, which works great most of the time:
xq = 0:360;
for n = 1:size(pr_transpose, 1)
p{n} = pr_transpose(n, :);
s{n} = sr_transpose(n, :);
% Remove NaN values from the input arrays
validIndices = ~isnan(p{n}) & ~isnan(s{n});
% Perform interpolation only using non-NaN values
sr{n} = interp1(p{n}(validIndices), s{n}(validIndices), xq);
end
% Concatenate interpolated data from all rows
s_data = vertcat(sr{:});
However, I have a couple of trials of this dataset which feature a duplicate number! Which the interp1 function does not like as it requires that the data points to be unique. The following error message is shown:
Error using matlab.internal.math.interp1
Sample points must be unique.
I have the issue that I cannot alter the data by removing this point, so I think that I may need to change my approach. I identified the repeated number in the attached example data as being pr_transpose(1,17) by using the following:
[v, w] = unique( (pr_transpose(1,:)), 'stable' );
duplicate_indices = setdiff( 1:numel(pr_transpose(1,:)), w )
I have tried to use the resample function but I could not seem to get it to work. I don't think I can use the interp1 function without altering the data and removing the data point (which I can't do). I am probably just not approaching this from the right angle, so I would appreciate some input! Please let me know if you need any further information. Thank you!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Multirate Signal Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!