Effacer les filtres
Effacer les filtres

Interpolating each row of a matrix with NaN values

4 vues (au cours des 30 derniers jours)
Kacey Lange
Kacey Lange le 15 Juin 2022
Commenté : Star Strider le 15 Juin 2022
I curently have a matrix 'VSFv' with a size of 30x173, with each row a different line, corresponding to my 30 samples. There are negative numbers, creating segmented lines in some samples. I am trying to interpolate those segmented lines to create one continuous line, replacing the negative numbers in each row in a for loop. I am able to do it with one row (row 18) with the corresponding code:
inter = VSFv(18,:);
inter(inter<0) = NaN;
interp = ~isnan(inter);
ave = cumsum(interp-diff([1,interp])/2);
final = interp1(1:nnz(interp),inter(interp),ave);
The for loop that I am trying to work out is:
for j=1:1:size(T,1)/2
inter(j,:) = VSFv(j,:);
inter(inter<0) = NaN;
interp(j,:) = ~isnan(inter(j,:));
ave(j,:) = cumsum(interp(j,:)-diff([1,interp(j,:)])/2);
F(j,:) = interp1((interp(j,:)),inter(interp),ave(j,:));
end
Where j=30, inter is my matrix with NaNs instead of negative numbers, and ave is my query vector. I get the error
"Error using interp1>reshapeAndSortXandV (line 424)
X and V must be of the same length."
I also tried using 'griddedInterpolant' code too, but had no luck. Can anyone help?

Réponse acceptée

Star Strider
Star Strider le 15 Juin 2022
I am not certain that I understand the problem, however if the intent is to interpolate the NaN values, see if the fillmissing function (introduced in R2016b) will do what you want.
  2 commentaires
Kacey Lange
Kacey Lange le 15 Juin 2022
Just tried it and it worked! Used this:
F(j,:) = fillmissing(inter(j,:),'movmedian',10);
Which fixed my problem. Thank you!
Star Strider
Star Strider le 15 Juin 2022
As always, my pleasure!

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