How to remove a certain value from all entries of a vector
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I have given different vectors by measuring mechanical stress in an experiment.
However, due to a measurement error, an offset occurred after a few seconds (see following picture):

Right now the code looks something like this:
x60l = Schnitt_60_1.Schnitt_60_1.Zeit;
x60 = x60l(1:end);
a60l = Schnitt_60_1.Schnitt_60_1.DMS_1;
a60 = a60l(1:end);
B2 = smoothdata(a60,"movmean","SmoothingFactor",0.2,"SamplePoints",x60);
plot(x60,B2,'Color','[1 0.5 0]','LineWidth',1.5)
Now I would like to delete the first values of my vector and adjust the remaining values so that the signal starts at 0 again (removing the offset). How can I do this?
Thank you in advance
0 Commenti
Risposte (2)
Cris LaPierre
il 15 Ott 2022
You might consider using the Remove Trends live task if you are working in a live script. This is limited to removing polynomial trends. The live task makes it easy to test different settings quickly to try and find one that works for you. You can see an example here.
2 Commenti
Cris LaPierre
il 15 Ott 2022
Just subtract a scalar value from all your data.
a60 = a60l(1:end) - 30;
You get to pick what the scalar value is.
Star Strider
il 15 Ott 2022
You can remove the offset and the trend with a highpass (or bandpass) filter. (Use bandpass if you want to elimiinate high-frequency noise as well.) For best results, use the 'ImpulseResponse','iir' name-value pair.
First use the fft or pspectrum function to understand the frequency content of the signal. This will allow you to determinne the filter stopbands correctly. It will likely be necessary to experiment to get the desired result.
All of these (except fft) require the Signal Processing Toolbox.
2 Commenti
Star Strider
il 15 Ott 2022
To subtract a specific value, MATLAB implicitly expands the operations automatically so it can be done in one operation —
x = 0:25; % Create Data
y1 = x+5 - x/100 + randn(size(x)); % Create Data
figure
plot(x, y1)
grid
ylim([-30 30])
y2 = y1 - 15; % Subtract Constant
figure
plot(x, y2)
grid
ylim([-30 30])
.
Vedere anche
Categorie
Scopri di più su Digital Filter Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

