Interpolating each row of a matrix with NaN values
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2022-6-15
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!