replace NaN value without disturb or remove important peak
4 次查看(过去 30 天)
显示 更早的评论
Here im attached my example data and plot image of the data, i have problem to replace the NaN value without disturb the ploting trend or remove important peak. Can anyone help me to solve this problem?
If you see from data im attach, the NaN value located something at center and the end of the data. i want to make the ploting to be continuous without remove number of data and try to keep the trend also important peak.

0 个评论
回答(2 个)
Star Strider
2025-4-9
编辑:Star Strider
2025-4-12
M1 = readmatrix('41679.2500000000.txt');
X1 = linspace(0, numel(M1), numel(M1)).';
FM1 = fillmissing(M1, 'linear');
Lv = isnan(M1);
nnz(Lv)
Lv1 = strfind(Lv.', [0 1]).'; % Segment Start Indices
Lv2 = [strfind(Lv.', [1 0]); numel(M1)]; % Segment End Indices
figure
plot(X1, M1)
hold on
for k = 1:numel(Lv1)
idxrng = Lv1(k) : Lv2(k);
plot(X1(idxrng), FM1(idxrng), '--r')
end
hold off
grid
.
EDIT — (9 Apr 2025 at 11:43)
Corrected typographical errors.
EDIT — (12 Apr 2026 at 13:23)
The interpolated vector ‘FM1’ has all the necessary values and no NaN gaps —
figure
plot(X1, FM1)
grid
.
0 个评论
Thorsten
2025-4-10
y = readmatrix('41679.2500000000.txt');
x = 1:numel(y);
yi = interp1(x(~isnan(y)), y(~isnan(y)), x, 'linear', 'extrap');
plot(x, yi)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!