Polyfit Ignoring NaN Values
34 ビュー (過去 30 日間)
古いコメントを表示
Hello!
I am trying to iterate over rows of a matrix (Z) and fit a curve to each row and then subtract the fitted curve from the original data, however all of my rows contain NaN values. I would like to somehow fit the curve ignoring the NaN values, to subtract this curve from my original matrix row of values. The result would be a matrix with the same dimensions as my original, with the curve subtracted from real values and NaN values in their original place holders. I have thought about indexing NaN values using isnan() and then applying the polyfit to values when isnan() == 0 but everything I've tried so far hasn't quite worked out.
This is what it looks like so far:
for j = 1:m;
nx = size(Z,2);
x = 1:nx;
p = polyfit(x,Z(j,:),2);
y = polyval(p,x)
Z(j,:) = Z(j,:) - y;
end
Thanks for your help!
0 件のコメント
採用された回答
Image Analyst
2017 年 11 月 24 日
Can you attach Z in a .mat file so we can try things? Like
for j = 1:m;
thisRow = Z(j, :);
nx = size(Z,2);
x = 1:nx;
nanIndexes = isnan(thisRow);
thisRow(nanIndexes) = [];
x2 = x(~nanIndexes)
p = polyfit(x2,thisRow,2);
y = polyval(p,x)
Z(j,:) = Z(j,:) - y;
end
but that's just off the top of my head. would be easier if we had your Z.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!