Smoothing just part of the data

21 Ansichten (letzte 30 Tage)
KuriGohan
KuriGohan am 11 Apr. 2022
Kommentiert: John D'Errico am 12 Apr. 2022
I have a 5000x1 array. I'd like to smooth the data from 500:1500 with the function smooth. For now i have created another array 1000x1 with the smoothed data and then overwritten the 500:1500 data in the original array, but is there an easier way to do it?

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 11 Apr. 2022
Bearbeitet: KALYAN ACHARJYA am 11 Apr. 2022
One way
data=rand(5000,1);
data_smooth=data; % Just copy to retain original data
data_ex=smoothdata(data(500:1500));
data_smooth(500:1500)=data_ex;
You can plot both that data, data & data_smooth to see the difference.
  1 Kommentar
KuriGohan
KuriGohan am 12 Apr. 2022
yes, thats similar to how i do it now. I just didn't copy to retain original data, i'll add that too. Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

John D'Errico
John D'Errico am 11 Apr. 2022
Um, No. Why should there be?
In fact, extracting the part you want to smooth, and then overwriting that smoothed fragment back into the array seems crystal clear, easy to implement, easy to debug, easy to read, and as fast an any other scheme could be. So why should there be another way?
  2 Kommentare
KuriGohan
KuriGohan am 12 Apr. 2022
Yes that is right, however i have a lot of arrays and i was just wondering if there was a way that is a bit more elegant/requiers less code.
John D'Errico
John D'Errico am 12 Apr. 2022
So write a little function that does it for you, extracting that segment only, then replacing it after the smooth. Now you can call it as often as you wish. Write the function to take data as an argument, and a second argument that indicates the specific interval. Have it do the smooth and replacement.
This is how MATLAB works. If you want something there is absolutely no general need for, then nobody will have writtten something as specific as this. In that case, you write a function that does it for you.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by