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.

回答(2 个)

Star Strider
Star Strider 2025-4-9
编辑:Star Strider 2025-4-12
One option is to use the fillmissing function and then plot the filled segments appropriately —
M1 = readmatrix('41679.2500000000.txt');
X1 = linspace(0, numel(M1), numel(M1)).';
FM1 = fillmissing(M1, 'linear');
Lv = isnan(M1);
nnz(Lv)
ans = 57000
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
.

Thorsten
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)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by