replace NaN value without disturb or remove important peak

조회 수: 4 (최근 30일)
raja adibah
raja adibah 2025년 4월 9일
편집: Star Strider 2025년 4월 12일
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