Calculate weekly mean from temperature data
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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!
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!