How can I use cubic spline to smooth data and sketch graphs.

Hi.
I have large sets of data where I need to use cubic spline to apply smoothing and sketch the graph. In my data I need to find the average of total vertical electron content (VTEC) and come up with one hourly value using cubic spline and than sketch the against time for a period of 24hrs for every month. I'm new to matlab software and any help and suggestions is highly appriciated. Please find attached the set of sample data that i need to analyse for month of Feb. Thank you.

2 commentaires

John D'Errico
John D'Errico le 8 Nov 2021
Modifié(e) : John D'Errico le 8 Nov 2021
You don't use a cubic spline to average data at a given point. You really want to do that BEFORE you use a cubic spline.
Next, a cubic spline is typically an INTERPOLATING spline, so it won't smooth your data. It will pass directly through the data points.
Finally, you did NOT attach any data. You attached a small PICTURE of your data, which is completely useless unless someone were to try to type in your complete data set. I hope they have very good eyesight if they do. Is there a good reason why you want to make it more difficult for someone to help you?
If you really want help, then it would be best if you actually attach the true data. Do so either by pasting in the data as text, or by attaching a .mat file. A spreadsheet is also acceptable, but it takes slightly more effort for someone to read it in, IF they were going to try to help you. Again, is there a good reason why you want to make it difficult to get timely help? Please edit your question, or attach your data to a comment on your question. (Do not answer your question with the data, as many seem to do.)
Appologies for any inconvenience. I have attached the spreadsheet file. Please suggest any suitable method to analyse this data set. Thank you.

Connectez-vous pour commenter.

 Réponse acceptée

hello
example of smoothing done on L1 data - FYI -
clc
clearvars
T = readtable('Feb 2020_Elv 50+.csv');
[samples,col] = size(T);
x = (0:samples-1);
L1 = T.L1;
L1s = smoothdata(L1,'movmedian',17);
plot(x,L1,x,L1s)
legend('raw','smoothdata')

12 commentaires

Vikash Raj
Vikash Raj le 9 Nov 2021
Modifié(e) : Vikash Raj le 9 Nov 2021
Thank you. The plots looks good.
What sets of code I can write to smooth the data after improting only Time and Absolute_ Vtec in matlab and than apply the smoothing as you have done above ? I was trying but getting an error. Im using R2015a version.
hello
what is the error message ?
does R2015a have the smoothdata function ? there are some alternatives
Vikash Raj
Vikash Raj le 10 Nov 2021
Modifié(e) : Vikash Raj le 10 Nov 2021
the error is ''Undefined function or variable 'smoothdata' ''
It does not have smoothdata function. It only has "smooth" function.
hello
this is an alternative using smoothn (from FEX : smoothn - File Exchange - MATLAB Central (mathworks.com) - attached also for convenience
plot is :
code :
clc
clearvars
T = readtable('Feb 2020_Elv 50+.csv');
[samples,col] = size(T);
x = (0:samples-1);
L1 = T.L1;
L1s = smoothn(L1,200,'robust');
plot(x,L1,x,L1s)
legend('raw','smoothn')
Hi,
Even smoothn returns the error.
mamma mia !
what's wrong this time ?
what is the error message ?
Hi,
the error is ''Undefined function or variable 'smoothn';
Instead of using 'smoothdata' and 'smoothn' I have tried with 'smooth' it was not giving any error.
I was reading a journal article where it was suggested that Total electron data can be smooth using cubic smoothing spline (csaps). Any suggestions How I can impelement this. Thank you.
hello
I sent yu in my previous post the infos about
it was also attached (again here)
hello
this is an alternative using smoothn (from FEX : smoothn - File Exchange - MATLAB Central (mathworks.com) - attached also for convenience
you have to save that function in your working directory or in your matlab path
If you have the Curve fitting toolbox the csaps function (and others) are available
Thank you for your suggestions

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by