smoothing datasets containg nan

how i can smooth these data :
data=[1 1.927259
2 1.519675
3 2.553609
4 3.138377
5 3.6647
6 6.6849
7 6.937631
8 6.087666
9 nan
10 9.182496
11 9.536923
12 8.610497
13 8.3172
14 17.25756
15 6.725476
16 18.0788
17 8.0282
18 9.9958
19 7.063844
20 5.164532
21 3.5716
22 2.296498
23 1.757754
24 1.559203];

回答 (2 件)

Les Beckham
Les Beckham 2023 年 10 月 30 日

0 投票

Interestingly, the default window size for the 'sgolay' smoothing method in the smoothdata function generates smoothed data that is indistinguishable from the original data in this case.
Below, I've made a slight modification to the answer I gave to your previous question (found here):
I added the window size optional argument to the smoothdata call below. Adjust as desired. Or, experiment with other smoothing methods. See the link above to the documentation.
data=[ ...
1 1.927259
2 1.519675
3 2.553609
4 3.138377
5 3.6647
6 6.6849
7 6.937631
8 6.087666
9 nan
10 9.182496
11 9.536923
12 8.610497
13 8.3172
14 17.25756
15 6.725476
16 18.0788
17 8.0282
18 9.9958
19 7.063844
20 5.164532
21 3.5716
22 2.296498
23 1.757754
24 1.559203];
plot(data(:,1), data(:,2))
hold on
window_size = 8; % <<< experiment with adjusting this to get results that you like
sm_data = smoothdata(data(:,2), 'sgolay', window_size); % save the smoothed data
plot(data(:,1), sm_data)
grid on
legend('original data', 'smoothed data')
Also, please don't close questions minutes after posting them. Give people a chance to answer them.

7 件のコメント

ahmad Saad
ahmad Saad 2023 年 10 月 30 日
Deep thanks for attention and kind help.
I apologize. Not me, probably MathWorks does.
ahmad Saad
ahmad Saad 2023 年 10 月 30 日
are there other methods that can do perfect smoothing
Les Beckham
Les Beckham 2023 年 10 月 30 日
You are quite welcome. Don't forget to Accept the answer if it solved your issue.
What would you consider "perfect smoothing"?
There are lots of methods of smoothing data in Matlab (some of which require additional toolboxes).
Just use your favorite search engine or the Matlab documentation search tool to explore your options.
ahmad Saad
ahmad Saad 2023 年 10 月 30 日
thanks again
i consider smoothing means not to have broken lines
Les Beckham
Les Beckham 2023 年 10 月 30 日
If filling in gaps in your data is your primary goal (rather than smoothing out jagged parts of the curve), I would recommend reading the documentation for fillmissing. That function can also do some smoothing of the jagged parts, like smoothdata.
Here is an example using this set of data, just filling in the gaps using linear interpolation.
Note that I swapped the order of the plots (plotting the original data on top of the smoothed data to make it more obvious where the gap was).
data=[ ...
1 1.927259
2 1.519675
3 2.553609
4 3.138377
5 3.6647
6 6.6849
7 6.937631
8 6.087666
9 nan
10 9.182496
11 9.536923
12 8.610497
13 8.3172
14 17.25756
15 6.725476
16 18.0788
17 8.0282
18 9.9958
19 7.063844
20 5.164532
21 3.5716
22 2.296498
23 1.757754
24 1.559203];
sm_data = fillmissing(data(:,2), 'linear'); % save the smoothed data
plot(data(:,1), sm_data)
hold on
plot(data(:,1), data(:,2), 'o-')
grid on
legend('smoothed data', 'original data')
ahmad Saad
ahmad Saad 2023 年 10 月 30 日
thanks again for your kind attention.
Actually, i need to smooth the data not to fill the gaps.
Image Analyst
Image Analyst 2023 年 10 月 30 日
Well the obvious thing to do is to fill the gaps (which you said once that you needed to do), and then after that smooth the data.

サインインしてコメントする。

Image Analyst
Image Analyst 2023 年 10 月 30 日

0 投票

Have you seen the "DataCleaner" app on the Apps tab of the tool ribbon? Try it.

2 件のコメント

ahmad Saad
ahmad Saad 2023 年 10 月 30 日
Thanks for response.
Unfortunally, I havent this app
Image Analyst
Image Analyst 2023 年 10 月 31 日
編集済み: Image Analyst 2023 年 10 月 31 日
Yes you do. It's included in base MATLAB. Did you go to the Apps tab? Did you click on the little down arrow on the very right side of the group of all the applet icons? Look in the group/row called "MATLAB". See image below.

サインインしてコメントする。

質問済み:

2023 年 10 月 30 日

編集済み:

2023 年 10 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by