필터 지우기
필터 지우기

3hr time avarage plot of data

조회 수: 1 (최근 30일)
root
root 2023년 3월 27일
댓글: root 2023년 3월 27일
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

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 3월 27일
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
Cris LaPierre
Cris LaPierre 2023년 3월 27일
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
root
root 2023년 3월 27일
I am using Matlab_R2020b version.
And now, it worked. Thank you so much!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pulsed Waveforms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by