필터 지우기
필터 지우기

Calculate weekly mean from temperature data

조회 수: 4 (최근 30일)
Giulia
Giulia 2023년 3월 31일
댓글: Giulia 2023년 4월 4일
Hi!
Can anyone help me to calculate weekly means of temperature data (td= SST - bottom temp difference) and salinity data? Time is from 1st of July till 31st of August 2022 (hour 12:00:00 for every day).
Could not attach the data as mat files they are too big. My variables include:
td(temperature difference) =783x1230x62 double
sal=4-D double
time = 62x1 datetime
My friend used this code for the same procedure, but I need to change the number of weeks as it's different from my data (she had 13 weeks). I also don't know how to interpret what she did in the calculations ( (w-1)*7+1:w*7) ) so don't know how to apply it to my data. Thanks in advance!
for w = 1:13
tdw(:,:,w) = mean(td(:,:,(w-1)*7+1:w*7),3);
salw(:,:,:,w) = mean(sal(:,:,:,(w-1)*7+1:w*7),4);
end

채택된 답변

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 3월 31일
편집: Antoni Garcia-Herreros 2023년 4월 4일
Hello Giulia,
You may try something like this.
If you need more info on conditional statements, you can refer to this page
td=rand(783,1230,62); %Generate variables for the example
sal=rand(783,1230,3,62);
l=1:7:size(td,3); % Indices to separate the days in the week e.g. 1 8 15 ...
tdw=zeros([size(td,[1 2]) size(l,2)]); % Array where the means of td for every week will be stored
salw=zeros([size(sal,[1 2 3]) size(l,2)]); %Same but for sal
for i=1:numel(l) %Loop through the first day of the weeks 1 8 15 ...
if i+1>numel(l) % This will only be true for the last week. Because if we call l(i+1) it will give us an error
% And because the last week is not 7 days, we take the mean of td
% and sal from day l(end), 57, to end of td, 62
tdw(:,:,i)=mean(td(:,:,l(i):end),3);
salw(:,:,:,i) = mean(sal(:,:,:,l(i):end),4);
else % The rest of the iterations will enter here, where we take the mean between of td or sal between the first and last day of week i
tdw(:,:,i)=mean(td(:,:,l(i):l(i+1)-1),3);
salw(:,:,:,i) = mean(sal(:,:,:,l(i):l(i+1)-1),4);
end
end
Hope this helps!
  댓글 수: 3
Giulia
Giulia 2023년 4월 4일
Hi again Antoni, just as a clarification as I am quite new to Matlab...what is the 'if ... else ... end' statement used for? Thanks!
Giulia
Giulia 2023년 4월 4일
Thanks again for the clarification!
Best

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by