필터 지우기
필터 지우기

I need to find the mean and nanmean of sigma0 of 68th julian day( a single day) containing 52 datasets.

조회 수: 1 (최근 30일)
% i have tried a for loop ,donno whether it is correct or not For i=1:length(allfiles) fname=allfiles(abc).name jd=str2double(fname(14:16)); jd_vector(i)=jd idx= find(jd_vector==i) mean_data(i)=mean(idx); % also i need to find out the mean of Sigma0 for 52 datas.the 52 files have been read by the (i) function.and also while reading the mean_data values,it is shown as Nan (is this correct or not,iam bit confused)is there any code for finding the variable sigma0 as a continuation of this loop?

답변 (1개)

Abhishek Krishna
Abhishek Krishna 2023년 6월 19일
Hi,
In order to find the mean and nanmean, consider changing your code as per the below suggestions and hope it helps to resolve your query.
Firstly, replace “abc” with "i" to succesfully iterate through the files listed in the "allfiles" array. Also, modify the line "idx= find(jd_vector==i)" to "idx= find(jd_vector==jd)" to correctly find the index of the Julian date in the "jd_vector" array.
Regarding the computation of the mean of Sigma0 for the 52 files, consider adding the following code inside the ‘for loop’ after the creation of the "fname" variable:
% Read the data from the current file
data = load(fname);
% Select only the Sigma0 values from the data
sigma0_values = data(:,2);
% Calculate the mean of Sigma0 for this file
sigma0_mean = mean(sigma0_values);
% Add the mean to a running total
sigma0_total = sigma0_total + sigma0_mean;
This code assumes that the Sigma0 values are stored in the second column of the data file and that each file contains the same number of rows for consistency. Finally, to compute the overall mean of Sigma0 after processing all 52 files, consider add the following code after the ‘for loop’:
% Calculate the overall mean of Sigma0
sigma0_mean = sigma0_total / 52;
The root-cause of "mean_data" variable displaying NaN values, is likely due to "idx" being empty if there are no elements in "jd_vector" matching the current Julian date. In this case, "mean_data(i)" will indeed become NaN. To avoid this, you can check whether "idx" is empty before computing the mean and assign a default value, if necessary, like so:
if isempty(idx)
mean_data(i) = 0; % Or any other default value
else
mean_data(i) = mean(idx);
end

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by