How to remove a certain value from all entries of a vector

4 views (last 30 days)
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

Answers (2)

Cris LaPierre
Cris LaPierre on 15 Oct 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 Comments
Elias Klee
Elias Klee on 15 Oct 2022
Elias Klee weniger als eine Minute ago
Hi,
I am really just a beginner when it comes to MatLab. That's why I was hoping for a little more intentional approach, such as subtracting a specific scalar of every value of the vector a60 in order to remove the offset.
I don't really feel like removing trends is what I am trying to do.
Do you have any ideas how to remove the offset (which is not a trend in my understanding) in a little more vector-oriented way?
Thanks a lot anyways for your answer
Cris LaPierre
Cris LaPierre on 15 Oct 2022
Just subtract a scalar value from all your data.
a60 = a60l(1:end) - 30;
You get to pick what the scalar value is.

Sign in to comment.


Star Strider
Star Strider on 15 Oct 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 Comments
Elias Klee
Elias Klee on 15 Oct 2022
Hi,
I am really just a beginner when it comes to MatLab. That's why I was hoping for a little more intentional approach, such as subtracting a specific scalar of every value of the vector a60 in order to remove the offset.
I don't really have the need to filter out specific frequencies nor to remove a trend. Do you have any ideas how to do it in a little more vector-oriented way?
Thanks a lot anyways for your answer
Star Strider
Star Strider on 15 Oct 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])
.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!