I have a graph as follows. I am looking to replace the valley (red) with smoothened data. Is there a way to do this? I am unaware of the best method of achieving this currently.
this would be me suggestion if the idea is to replace the "faulty" data segment with a piecewise linear segment and then do a further smoothing
%--- Example #2: smooth a curve / wide valley removal ---
x = linspace(0,100,256);
y = cos(x/10)+(x/50).^2;
y([70:120]) = - 2;
y = y+ randn(size(x))/10;
yy = y;
% define segment to be removed based on sharp slope changes
dy = gradient(y);
% remove bad data "in the valley"
[val_min,ind_min] = min(dy);
[val_max,ind_max] = max(dy);
ind_offset = 2; % expand a bit the data segment beyond the limits ind_min / ind_max => ind_min-ind_offset / ind_max+ind_offset
y(ind_min-ind_offset:ind_max+ind_offset) = linspace(y(ind_min-ind_offset),y(ind_max+ind_offset),ind_max-ind_min+1+2*ind_offset); % replace outliers by linear segment
N = 25;
ys = smoothdata(y,'gaussian',N);
figure (3);
plot(x,yy,'b',x,y,'k',x,ys,'r-.','LineWidth',2);
legend('raw data','interpolated data','interpolated and smoothed data')
now there is another possibility is to "shift" upwards this segement (if we want to keep the data) and do a smoothing as well
%--- Example #3: shift the "valley" to be (more or less) aligned with rest of data ---
x = linspace(0,100,256);
y = cos(x/10)+(x/50).^2;
y([70:120]) = - 2;
y = y+ randn(size(x))/10;
yy = y;
% define segment to be shifted based on sharp slope changes
dy = gradient(y);
% remove bad data "in the valley"
[val_min,ind_min] = min(dy);
[val_max,ind_max] = max(dy);
ind_offset1 = 0; % expand a bit the data segment beyond the limits ind_min / ind_max => ind_min-ind_offset / ind_max+ind_offset
ind_offset2 = 0; % expand a bit the data segment beyond the limits ind_min / ind_max => ind_min-ind_offset / ind_max+ind_offset
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Translated by
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.