Azzera filtri
Azzera filtri

Interpolating each row of a matrix with NaN values

4 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Star Strider
Star Strider il 15 Giu 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 Commenti
Kacey Lange
Kacey Lange il 15 Giu 2022
Just tried it and it worked! Used this:
F(j,:) = fillmissing(inter(j,:),'movmedian',10);
Which fixed my problem. Thank you!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Interpolation 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!

Translated by