3hr time avarage plot of data
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone
I am trying to plot .cdf file with a 3hr moving avaerage and i started the code as follwos . I couldnt attach the data as it says data format is not supported. But here is the website to get the data from
"https://swarm-diss.eo.esa.int/#swarm%2FAdvanced%2FPlasma_Data%2F2_Hz_Langmuir_Probe_Extended_Dataset%2FSat_A"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=('SW_EXTD_EFIA_LP_HM_20131216T000000_20131216T235959_0106.cdf');
Ne = cell2mat(cdfread(data,'Variables',{'n'})); % Electron density
ti=(cdfread(data,'Variables',{'Timestamp'})); % Time
%%%%%%%%%%%%%%%%%%%%%% Time conversion to get HH:MM:SS format
for k=1:length(ti)
datenum2(k) = todatenum(ti{k});
end
T = datetime(datenum2, 'Format','HH:mm:ss', 'ConvertFrom','excel');
t1=T';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
avg_Ne = movmean(Ne, 3*60*60/median(diff(t1)));
plot(t1, avg_Ne);
xlabel('Time');
ylabel('Ne');
title('3-Hour Time Average');
%%%%%%%%% The Error I am having
Error using cdf_3hr_average (line 82)
The denominator in matrix division for duration
arrays must be a real scalar double value.
I would be happy to hear any comments .
Thank you
0 Commenti
Risposta accettata
Cris LaPierre
il 27 Mar 2023
This problem is made much simpler if you leverage the capabilities of cdfread. It can read in cdfepochs as datetimes, simplifiing that step. You can then use movmean to create a 3-hour moving mean (see this example).
% Obtain info about what is in the CDF file
filename = "SW_EXTD_EFIA_LP_HM_20131216T000000_20131216T235959_0106.cdf";
ci = cdfinfo(filename)
ci.Variables
% Load the specified variables
data = cdfread(filename,'Variables',{'n','Timestamp'},"DatetimeType","datetime"); % Electron density, Time
Ne = vertcat(data{:,1}); % Electron density
ti = vertcat(data{:,2}); % Time
% compute a 3 hour moving mean
avg_Ne = movmean(Ne, hours(3), 'SamplePoints', ti)
% Visualize
plot(ti, avg_Ne);
xlabel('Time');
ylabel('Ne');
title('3-Hour Time Average');
Since the data is too large to load here, here is a screenshot of what the final plot looked like for me. I have not gone through the data to verify any of the results.
5 Commenti
Cris LaPierre
il 27 Mar 2023
If you are using a pre-R2022b version of MATLAB, try using this instead
% pre R2022b (no DatetimeType option)
data = cdfread(filename,'Variables',{'n','Timestamp'},"ConvertEpochToDatenum",true); % Electron density, Time
Ne = vertcat(data{:,1}); % Electron density
ti = datetime(vertcat(data{:,2}),"ConvertFrom","datenum"); % Time
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!