Interpolating each row of a matrix with NaN values
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kacey Lange
am 15 Jun. 2022
Kommentiert: Star Strider
am 15 Jun. 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?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 15 Jun. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!