How to treat a duration array in a for loop?

5 次查看(过去 30 天)
My overall goal: I have measurements from different sensors which are performed simoultaneously, but with different timesteps. Now, I want to use both outputs in order to do some calculations.
So, I need to calculate mean values from some measurements (e.g. timesteps of each 10sec) in order to put them into the same format likewise the other measurements (timesteps of each 10min). In the end I want to have the different measurements with equal timesteps.
Hence, one table and its timesteps represent a pattern, and I want to convert the other table into the same pattern with regard to the timesteps.
Therefore, I have started to build up a for loop to write a table with (1) the timesteps and (2) the corresponding calculated mean values. I have started with the timesteps, but I am facing an issue with the duration array within this for loop. It gives me "Error using duration/double".
My short code so far:
%% read input file (csv) and determine output path
in_timesteps = 'C:\Users\Judith\Desktop\phd\Data\Hukseflux\Calculations\26.07.2021_28.07.2021_calc_Enet.csv';
in_measured = 'C:\Users\Judith\Desktop\phd\Data\daten_wetterstation\WL__2021_07_27.csv';
measure_day = '27.07.2021';
output = 'C:\Users\Judith\Desktop\phd\Data\Hukseflux\Calculations\';
data_timesteps = readtable(in_timesteps, 'NumHeaderLines', 0, 'Delimiter', ',' ,'DecimalSeparator', '.', "VariableNamingRule" , "preserve");
data_measured = readtable(in_measured, 'NumHeaderLines', 0, 'Delimiter', ',' ,'DecimalSeparator', '.', "VariableNamingRule" , "preserve");
data_measured.Properties.VariableNames = regexprep(data_measured.Properties.VariableNames, ' ', '_');
%date = unique(data_timesteps.Date);
%%
ind_dt = find(data_timesteps.Date == measure_day);
H = zeros(sum(data_timesteps.Date == measure_day),2);
for i = 1:(sum(data_timesteps.Date == measure_day))
H(i,1) = data_timesteps.Time(ind_dt(i))
end
%%
% ind_time = find(data_measured.Time > data_timesteps.Time(1) & data_measured.Time < data_timesteps.Time(2) & data_measured.Date == measure_day);
% x = mean(data_measured.WD__Avr(ind_time));
% new_table = table(data_timesteps.Time(2), x);
Any help is very much appreciated.
  1 个评论
JMSE
JMSE 2021-8-3
I have found an easier way to do this:
t = table(data_timesteps.Time(ind_dt),zeros(sum(data_timesteps.Date == measure_day)));
Thank you, anyways.

请先登录,再进行评论。

采纳的回答

Peter Perkins
Peter Perkins 2021-8-3
Judith, I can't really follow what you are doing, but if you have timestamped data, you should be using a timetable, and then retime makes aggregation (what it looks like you are doing) a one-liner, perhaps something like:
tt2 = retime(tt,'daily','sum')
If you have two timetables, synchronizes makes matching them up by time a one liner, perhaps something like
tt12 = synchronize(tt1,tt2,'first','linear')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by